Skip to content

Instantly share code, notes, and snippets.

@ovaillancourt
Created August 2, 2013 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovaillancourt/6143828 to your computer and use it in GitHub Desktop.
Save ovaillancourt/6143828 to your computer and use it in GitHub Desktop.
var EventEmitter = require( 'events' ).EventEmitter;
var emitter = new EventEmitter();
// SECTION-NAME
////////////////////////////////////////////////////////////////////////////////
function emitterClass(){
EventEmitter.call( this );
}
emitterClass.prototype = Object.create( EventEmitter.prototype );
emitterClass.prototype.emitEvent = function(){
this.emit( 'event!' );
}
// REceiver
////////////////////////////////////////////////////////////////////////////////
function receiverClass( e ){
e.on( 'event!', this.onEvent.bind( this ) );
}
receiverClass.prototype.onEvent = function(){
console.log( 'got event!' );
}
// Run
////////////////////////////////////////////////////////////////////////////////
var e = new emitterClass();
var r = new receiverClass( e );
e.emitEvent();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment