Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js中的event.currenttarget 和 this的区别 #2

Open
Hancoson opened this issue May 5, 2016 · 0 comments
Open

js中的event.currenttarget 和 this的区别 #2

Hancoson opened this issue May 5, 2016 · 0 comments

Comments

@Hancoson
Copy link
Owner

Hancoson commented May 5, 2016

前几天在使用ES6的时候发现箭头函数中,事件无法通过this获取本身,后来查了一些资料是这样的:

一般来说,thisevent.currentTarget是一致的。
但是,如果使用了某种作用域替换,(比如jquery.Proxy,或者 ES6CoffeeScript 等里用了 =>),this可能有别的含义了,用 event.currentTarget 就更安全。
一般人们更容易混淆的是 event.targetevent.currentTarget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant