removeListenersAnd removeAllListeners

 const events = require('events');

const e = new events.EventEmitter();

function Event1CallBackFun() {
console.log('Event1');
}
e.on('Event1',Event1CallBackFun)
e.on('Event1',function () {
console.log(`new no call back function.`);
})

e.on('Event2',function () {
console.log('Event2');
})

//====call==
e.emit('Event1');
/*
* Event1
new no call back function.
* */
e.emit('Event2');
//Event2

//==Remove Event1
try{
e.removeAllListeners('Event1');
}catch (e) {
console.log(e)
}
//e.removeListener('Event1',Event1CallBackFun)
//====call==
e.emit('Event1');//no outpute
e.emit('Event2');//only show Event2

Comments

Popular posts from this blog

App 1st User Define Component

Example 1

Rabiit