this指向

1:在全局作用域下 this对象指向的是window对象

console.log(this)//全局作用域

  控制台打印

 

 

 

2.在函数作用域下  

在非严格模式下:  this的指向依旧是window对象

function text(){
     console.log(this)
}
text()//当前函数无具体指向

控制台打印

在严格模式下:

this的指向是undefined

 

 

3:在对象里面

this的指向是当前该对象

 

posted @ 2020-12-21 19:37  刘葵  阅读(33)  评论(0编辑  收藏  举报