Created
July 31, 2014 04:03
-
-
Save mygoare/61dc8c1e5279b9c32c2c to your computer and use it in GitHub Desktop.
javascript eventEmitter
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
var events = require('events'); | |
function Door(colour) { | |
this.colour = colour; | |
events.EventEmitter.call(this); | |
this.open = function() | |
{ | |
this.emit('open'); | |
} | |
} | |
Door.prototype.__proto__ = events.EventEmitter.prototype; | |
var frontDoor = new Door('brown'); | |
frontDoor.on('open', function() { | |
console.log('ring ring ring'); | |
}); | |
frontDoor.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment