Thursday, 4 October 2018

node.js: emitter.eventNames()

emitter.eventNames()
Returns an array listing the events for which the emitter has registered listeners.

HelloWorld.js

var EventEmitter = require('events').EventEmitter;

var emitter = new EventEmitter();

emitter.on("welcome", (name) => {
 console.log("Hello Mr.%s", name);
});

emitter.on("morning", (firstName, lastName) => {
 console.log("Good Morning Mr.%s %s", firstName, lastName);
});

console.log(emitter.eventNames());

Output
[ 'welcome', 'morning' ]


Previous                                                 Next                                                 Home

No comments:

Post a Comment