Created
December 19, 2015 09:27
-
-
Save dino-su/d201f0aafdcc9c4f389c to your computer and use it in GitHub Desktop.
EventEmitter in composition way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var EventEmitter = require('events').EventEmitter; | |
var bot = { | |
sayHi: function(name) { | |
console.log('hi ' + name); | |
}, | |
emitter: new EventEmitter() | |
}; | |
bot.emitter.on('hello', function(name) { | |
console.log('hello ' + name); | |
}); | |
bot.sayHi('John'); | |
bot.emitter.emit('hello', 'John'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment