码迷,mamicode.com
首页 > 其他好文 > 详细

this的指向

时间:2017-01-20 15:36:08      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:back   meta   char   text   set   style   doctype   type   pre   

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>

</style>

</head>
<body>

<script type="text/javascript">
//this:1.当前发生事件的对象  2.当前的方法属于谁
var arr = [1,2,3,4];

arr.a = 12;

arr.show = function(){
    alert(this.a);// 弹出值为12,this就是arr
}
arr.show();


oDiv.onclick = function(){
    alert(this);//this代表oDiv
}

</script>
</body>
</html>

 

this的指向

标签:back   meta   char   text   set   style   doctype   type   pre   

原文地址:http://www.cnblogs.com/pjw2017/p/6322798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!