JavaScript.md 163. EventEmitter 实现 中 once方法实现存在函数this指向的问题
Kinvens opened this issue · 1 comments
Kinvens commented
once(event, callback) {
let wrapFun = (...args) =>{
callback(...args);
this.off(event, wrapFun);
};
this.on(event, wrapFun);
return this;
}
或者
once(event, callback) {
let _this=this
let wrapFun = function(...args) {
callback(...args);
_this.off(event, wrapFun);
};
this.on(event, wrapFun);
return this;
}
CavsZhouyou commented
感谢指正,已修改!