JavaScript中的this

今天深刻学习了JavaScript中的This使用,总结一下。

1.this凡是出现在方法中永远都是指向window对象.有以下情况

   function a(){

      alert(this) ;// 指向window对象

    }

   var b={

       x:10,

       y:20,

       z:function(){

           alert(this);//指向对象b

           function XX(){

                 alert(this);//指向window对象

           }

       }

    }

2.凡是定义在对象中的this指向对象本身.

   var  test={

   x:200,

   y:300,

   getX:function(){

       return this.x;//返回200

   }

   }

setinterval(1000,this.func())//指向windows对象

posted @ 2015-09-11 09:59  哥的头像很别致~  阅读(120)  评论(0编辑  收藏  举报