eventemitter3包的使用
安装: npm install eventemitter3
使用:
triggerEvent: function () {
new EventEmitter().on('someEvent', function (params) {
alert(params)
});
new EventEmitter().once('event-name', emitted, context);
new EventEmitter().on('another-event', emitted, context);
new EventEmitter().removeListener('another-event', emitted, context);
},
emitted: function() {
new EventEmitter().emit('someEvent', '触发事件');
}