body{ cursor: url("https://images.cnblogs.com/cnblogs_com/szqblog/1889956/o_201130135019Cursor.png"), auto; }

JS的this指向 笔记

this指向 一般指向调用它的对象

1. 全局作用域或者普通函数中,this指向window,(定时器中也是指向window)

function haha() {
   console.log(this)  //window
}
haha();

2. 谁调用this,指向谁

let shuaige = {
      name: function(){
               console.log(this)   //shuaigge
  }
}
shuaige.name();

 3. 函数中this指向构造函数的实例

function box (){

     console.log(this)    

}
box();   // window
  let Box = new box();  //function box();

欢迎讨论

 

posted @ 2019-09-17 17:33  1234前来报到  阅读(133)  评论(0编辑  收藏  举报