emitter.prependListener(eventName,
listener)
Prepend
a listener function to the beginning of the array for the event named
eventName.
var EventEmitter = require('events').EventEmitter; var emitter = new EventEmitter(); emitter.on('sayHello', () => { console.log('Hello Visitor'); }); emitter.emit('sayHello'); console.log('Prepended another listener function to the event "sayHello"'); emitter.prependListener('sayHello', (stream) => { console.log('Good Morning!!!!!!!'); }); emitter.emit('sayHello');
Output
Hello
Visitor
Prepended
another listener function to the event "sayHello"
Good
Morning!!!!!!!
Hello
Visitor
Note
a. This method returns a
reference to the EventEmitter, so that calls can be chained.
No comments:
Post a Comment