码迷,mamicode.com
首页 > 其他好文 > 详细

eventEmitter

时间:2014-10-16 14:49:52      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   cti   

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 ring
true
> 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 ring
true
> eventEmitter.emit(‘bbcry‘, ‘wade‘, 3);
bb wade 3
true
> 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 3
call daddy wade 3
true
> 

 

eventEmitter

标签:style   blog   color   io   ar   sp   div   on   cti   

原文地址:http://www.cnblogs.com/no7dw/p/4028510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!