Created
February 26, 2014 17:16
-
-
Save balamuru/9234035 to your computer and use it in GitHub Desktop.
This file contains 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 fs = require('fs'); // get the fs module | |
var EventEmitterVar = require('events').EventEmitter, util = require('util'); | |
var exampleEventEmitterClass= function () { | |
console.log("emitter constructor"); | |
} | |
util.inherits(exampleEventEmitterClass, EventEmitterVar); //register class as emitter | |
exampleEventEmitterClass.prototype.emitMethod1 = function () { | |
this.emit('emittedevent1'); | |
} ; | |
exampleEventEmitterClass.prototype.emitMethod2 = function () { | |
this.emit('emittedevent2'); | |
} ; | |
//register events | |
var evtEmitInstance = new exampleEventEmitterClass(); | |
evtEmitInstance | |
.on('emittedevent1', function () { | |
console.log('Executing Event Emitter 1'); | |
}) | |
.on('emittedevent2', function () { | |
console.log('Executing Event Emitter 2'); | |
} | |
); | |
for (var i = 0; i < 3; i++) { | |
evtEmitInstance.emitMethod1(); | |
} | |
for (var i = 0; i < 3; i++) { | |
evtEmitInstance.emitMethod2(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment