Skip to content

Instantly share code, notes, and snippets.

@dino-su
Created December 19, 2015 09:27
Show Gist options
  • Save dino-su/d201f0aafdcc9c4f389c to your computer and use it in GitHub Desktop.
Save dino-su/d201f0aafdcc9c4f389c to your computer and use it in GitHub Desktop.
EventEmitter in composition way.
'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