首页 > 代码库 > eventEmitter

eventEmitter

wade-mac:fin_server_invest mac$ node> var events =require(‘events‘)undefined> var eventEmitter = new events.EventEmitter();undefined> var ringBell = function ringBell()... {...   console.log(‘ring ring ring‘);... }undefined> eventEmitter.on(‘doorOpen‘, ringBell);{ domain: null,  _events: { doorOpen: [Function: ringBell] },  _maxListeners: 10 }> eventEmitter.emit(‘doorOpen‘)ring ring ringtrue> var ringBB = function ringBB(name, age){... console.log(‘bb‘, name, age);... }undefined> eventEmitter.on(‘bbcry‘, ringBB);{ domain: null,  _events:    { doorOpen: [Function: ringBell],     bbcry: [Function: ringBB] },  _maxListeners: 10 }> eventEmitter.emit(‘doorOpen‘);ring ring ringtrue> eventEmitter.emit(‘bbcry‘, ‘wade‘, 3);bb wade 3true> var callDaddy = function callDaddy(name,age){... console.log(‘call daddy‘, name, age);... }undefined> eventEmitter.on(‘bbcry‘,callDaddy);{ domain: null,  _events:    { doorOpen: [Function: ringBell],     bbcry:       [ [Function: ringBB],        [Function: callDaddy] ] },  _maxListeners: 10 }> eventEmitter.emit(‘bbcry‘, ‘wade‘, 3);bb wade 3call daddy wade 3true> 

 

eventEmitter