举个例子,用jQuery$('#test').on('click', ()=>{ console.log(this) // window});那我要怎么获取外部和内部的this?除了将箭头函数换成原来的function就没有其他方法了吗?
1 回答
![?](http://img1.sycdn.imooc.com/533e4d660001312002000200-100-100.jpg)
慕妹3146593
TA贡献1820条经验 获得超9个赞
es6中说到,箭头函数中没有自己的this:
this指向的固定化,并不是因为箭头函数内部有绑定this的机制,实际原因是箭头函数根本没有自己的this
官方也有说明:
Arrow functions capture the this value of the enclosing context
所有箭头函数通过call或者apply调用时传this也是没有效果的
添加回答
举报
0/150
提交
取消