Skip to content

Instantly share code, notes, and snippets.

@boutell
Created April 18, 2013 14:02
Show Gist options
  • Save boutell/5412937 to your computer and use it in GitHub Desktop.
Save boutell/5412937 to your computer and use it in GitHub Desktop.
How do I make my object an event emitter/receiver?
function Thing() {
var self = this;
// Thing is now an event emitter/receiver
require('events').EventEmitter.call(self);
}
var thing = new Thing();
thing.emit('foo');
// Expected result: no error
// Actual result: thing.emit('foo');
// ^
// TypeError: Object #<Thing> has no method 'emit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment