javascript - es6中this
高洛峰
高洛峰 2017-07-05 11:07:39
0
3
1004

Beginner es6
A previous click event was rewritten as $(".btn").click(()=>{console.log(this)});This here points to the document, but if When using function, this points to the current element. How to change the point of this?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
ringa_lee

It is recommended to take a look at the arrow function of es6

巴扎黑

The arrow function does not have its own this at all, but refers to the outer this

阿神

This question is a cliché. In conclusion, the this pointer in the arrow function has been fixed and points to the block-level scope of the current code rather than the caller's scope.

Some related documents:

https://developer.mozilla.org...

http://www.infoq.com/cn/artic...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template