Node.js EventEmitter: How to bind a class context to the event listener and then remove this listener
Is there a way to access to the class context in the event listener method with possibility to remove the listener? Example 1: import {EventEmitter} from "events"; export default class EventsExample1 { private emitter: EventEmitter; constructor(private text: string) { this.emitter = new EventEmitter(); this.emitter.addListener("test", this.handleTestEvent); this.emitter.emit("test"); } public dispose() { this.emitter.removeListener("test", this.handleTestEvent); } private handleTestEvent() { console.log(this.text); } } In this example removing the listener works, but the handleTestEvent()