首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。