Created
December 6, 2012 20:30
-
-
Save focusaurus/4228058 to your computer and use it in GitHub Desktop.
Emit events directly from a node module while also exporting functions
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 emitterModule = require('./emitter_module'); | |
emitterModule.on("e1", function () { | |
console.log("emitterModule.e1 handler invoked", arguments); | |
}); | |
emitterModule.func1(); |
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 util = require('util'); | |
function EmitterModule() { | |
EventEmitter.call(this); | |
} | |
util.inherits(EmitterModule, EventEmitter); | |
var _mod = new EmitterModule(); | |
_mod.func1 = function func1() { | |
console.log("emitter_module.func1 called, emitting e1"); | |
_mod.emit("e1", 42, 43); | |
}; | |
module.exports = _mod; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment