antvis/G2

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

xiaoke-1 posted onGitHub

  • 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?

这个功能应该怎么实现

<!-- generated by antv-issue-helper. DO NOT REMOVE -->


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

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

Fund this Issue

$0.00
Funded

Pull requests