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

react bind(this)相关问题 #4

Open
goldenYI opened this issue Jan 21, 2017 · 2 comments
Open

react bind(this)相关问题 #4

goldenYI opened this issue Jan 21, 2017 · 2 comments

Comments

@goldenYI
Copy link
Owner

No description provided.

@goldenYI
Copy link
Owner Author

需要注意,每个bind(this)都会动态生成, 即 a.bind(this) != a.bind(this)

若有
b() { addEventListener(event, a.bind(this)) }
但需要
c() { removeEventListener(event, a.bind(this)) }
这会导致不能remove掉,写了一个autobind,统一在construct中就一次性绑定,后不再做绑定,这样即可正常remove

@goldenYI goldenYI reopened this Jan 21, 2017
@goldenYI
Copy link
Owner Author

突然想起,如果bind中需要传递参数的话,原本应写成bind(this,...),要想一次性绑定如何解决传参问题

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