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

事件监听绑定了this怎么移除监听 #3807

Closed
1 task
xiaoke-1 opened this issue Feb 15, 2022 · 1 comment
Closed
1 task

事件监听绑定了this怎么移除监听 #3807

xiaoke-1 opened this issue Feb 15, 2022 · 1 comment

Comments

@xiaoke-1
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

在angular里使用图标,监听事件的回调函数需要绑定this,使用bind(this)或者匿名函数后,取消监听事件会判断为不是同一个函数,不能取消监听

What does the proposed API look like?

这个功能应该怎么实现

@hustcc
Copy link
Member

hustcc commented Jun 22, 2022

这是一个通用问题,其他的库中也会遇到类似的问题。解法其实很简单,就是把这个 function 存起来,有几种方式:

  1. function 挂到 this 上存起来
  2. function 放到全局,保证引用不变
  3. 技术栈中的一些方法可以保持引用,比如 React 中的 useCallback

@hustcc hustcc closed this as completed Jun 22, 2022
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

2 participants