函数调用
普通调用:this指向Window(在严格模式下,this指向undefined)
-
宽松模式
image.png
-
严格模式
image.png
隐示调用:this指向调用它的对象

显示调用:this指向call,aplay,bind的第一个参数

new(构造调用):this指向构造出来的实例对象

回调函数
事件回调函数:this指向绑定事件的DOM对象


普通回调函数(定时器,数组方法):this指向Window(在严格模式下,this指向undefined)

箭头函数
箭头函数:this指向离箭头函数最近的那个包裹函数的this,如果没有就指向Window

react,vue中的生命周期函数
生命周期函数的this指向组件对象
react中的自定义函数this指向undefined


** 注意:如果把handleClick()改为箭头函数,那么它的this指向组件对象,因为箭头函数的this指向包裹它的函数的this
ES6类中的方法
this指向实例对象
网友评论