Last active
October 17, 2016 04:05
-
-
Save fideloper/4651109 to your computer and use it in GitHub Desktop.
Using Event Emitter in your node modules
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 Fancy = require('FancyModule'); | |
var mod = new Fancy(); | |
mod.on('success', function(data) { | |
console.log(data); // { this_is_fancy:'indubitably' } | |
}); |
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; | |
function FancyModule() { | |
EventEmitter.call(this); | |
// And other fancy code | |
} | |
FancyModule.prototype = Object.create(EventEmitter.prototype); | |
FancyModule.prototype.fancified = function() { | |
// Just one of many fancy functions available in my fancy module | |
var fancyData = { this_is_fancy:'indubitably' }; | |
this.emit('success', fancyData); | |
} | |
module.exports = FancyModule; |
Author
fideloper
commented
Jan 27, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment