UNPKG

eventemitter4

Version:

EventEmitter4 is an alternative to node's built-in EventEmitter class, and to the existing alternatives EventEmitter2 and EventEmitter3

24 lines (18 loc) 540 B
var EventEmitter=require('../../index.js'); var emitter=new EventEmitter(); //Mum emitter.on('finished-eating',function(who) { console.log('clean up the table, '+who+'.'); }); //Mum emitter.on('finished-playing-ball',function(who) { console.log('go, take a shower, '+who+'.'); }); //john emitter.onAny(function(who) { if(who==='John') console.log('yes, mum'); }); emitter.emit('finished-eating','John'); emitter.emit('finished-playing-ball','John'); emitter.emit('finished-playing-ball','Ann');