Sunday 7 October 2018

node.js: emitter.listenerCount(eventName)

emitter.listenerCount(eventName)
Returns a copy of the array of listeners for the event named eventName.

HelloWorld.js
var util = require('util');

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

var emitter = new EventEmitter();

emitter.on('Hello', () =>{
 console.log("Hello World");
});

emitter.on('Hello', (name) => {
 console.log(`Hello Mr ${name}`);
})

console.log(util.inspect(emitter.listeners('Hello')));

Output
[ [Function], [Function] ]


Previous                                                 Next                                                 Home

No comments:

Post a Comment