Created
April 18, 2013 14:02
-
-
Save boutell/5412937 to your computer and use it in GitHub Desktop.
How do I make my object an event emitter/receiver?
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
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