Skip to content

Instantly share code, notes, and snippets.

@mygoare
Created July 31, 2014 04:03
Show Gist options
  • Save mygoare/61dc8c1e5279b9c32c2c to your computer and use it in GitHub Desktop.
Save mygoare/61dc8c1e5279b9c32c2c to your computer and use it in GitHub Desktop.
javascript eventEmitter
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