Skip to content

Instantly share code, notes, and snippets.

@joerx
Last active August 29, 2015 14:16
Show Gist options
  • Save joerx/436b57ea5c8772e0d16c to your computer and use it in GitHub Desktop.
Save joerx/436b57ea5c8772e0d16c to your computer and use it in GitHub Desktop.
EventEmitter
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
var obj = Object.create(EventEmitter.prototype);
obj.say = function say() {
obj.emit('hello');
}
obj.on('e', function() {
console.log('echo');
});
obj.on('hello', function() {
console.log('hello');
});
obj.emit('e');
obj.say();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment