Joo*_*oon 30

我自己找到了答案.

https://github.com/facebook/react-native/blob/235b16d93287061a09c4624e612b5dc4f960ce47/Libraries/vendor/emitter/EventEmitter.js

addListener返回EmitterSubscription扩展EventSubscription具有remove方法的实例.

https://github.com/facebook/react-native/blob/235b16d93287061a09c4624e612b5dc4f960ce47/Libraries/vendor/emitter/EventSubscription.js

const emitter = new EventEmitter();

const subscription = emitter.addListener('eventname', () => {});

subscription.remove(); // Removes the subscription
Run Code Online (Sandbox Code Playgroud)

  • this.listener.remove() 不是一个函数。 (2认同)