Created
August 2, 2013 22:03
-
-
Save ovaillancourt/6143828 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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