The "newListener" event does not fire

I am trying to experiment with some node event code.

Below is the code based on the docs "newListener" should fire every time before the listener is added to its internal array of listeners, But it does not work as expected.

Node version - v6.11.0

var event = require("events");
var events = new event.EventEmitter();

function FunHello(){
    console.log("Hello World !!!!!!!!");
}

function FunGreet(){
    console.log("Good Morning !!!!!!!!");
}

events.on("sayHello",FunHello);

events.on("sayHello",FunGreet);

events.addListener("hello",function(){
    console.log("hello hello !!!!");
});

/****** newListener is added *********/
events.on("newListener", function (evtName, fn) {
   console.log("New Listener: " + evtName);
});

events.emit("sayHello");

console.log("No of listerns for the event sayHello : " + events.listenerCount("sayHello"));

events.emit("hello");

The code is available at https://repl.it/Iqe4/0

+4
source share

Source: https://habr.com/ru/post/1679562/


All Articles