emitter.removeAllListeners([eventName])
Remove
all listeners associated with this event.
var EventEmitter = require('events').EventEmitter; var emitter = new EventEmitter(); emitter.on('sayHello', () => { console.log('Hello World'); }); emitter.on('sayHello', () => { console.log('Good Morning'); }); console.log('Emitting "sayHello" event'); emitter.emit('sayHello'); console.log('Removing all listeners for "sayHello" event'); emitter.removeAllListeners('sayHello'); console.log('Emitting "sayHello" event');
Output
Emitting
"sayHello" event
Hello
World
Good
Morning
Removing
all listeners for "sayHello" event
Emitting
"sayHello" event
No comments:
Post a Comment