Wednesday, 3 October 2018

EventEmitter: removeListener event

This event is emitted after the listener is removed.

Below table summarizes the arguments of callback function to removeListener event.
Argument
Type
Description
eventName
String
The name of the event being listened for
Listener
Function
Event handler function

Find the below working application.

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

var em = new EventEmitter();

var callback1 = () =>{
   console.log('callback1'); 
}

var callback2 = () =>{
   console.log('callback2'); 
}

em.on('demoEvent', callback1);
em.on('demoEvent', callback2);

em.on('removeListener', (eventName, listener) => {
 console.log(`listener, ${listener} is deleted for the event ${eventName} `)
});

em.removeListener('demoEvent', callback2);


Output
listener, () =>{
   console.log('callback2');
} is deleted for the event demoEvent




Previous                                                 Next                                                 Home

No comments:

Post a Comment