Created
October 30, 2012 12:19
-
-
Save mizanRahman/3979874 to your computer and use it in GitHub Desktop.
Play with node.js events. Make your own events.
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 EventEmitter = require('events').EventEmitter; | |
var util = require('util'); | |
// create the class | |
var MyClass = function () {} | |
util.inherits(MyClass, EventEmitter); | |
var obj = new MyClass(); | |
//add the listeners | |
obj.on('myevent',function(){ | |
console.log('my event emit'); | |
}); | |
obj.on('myevent',function(arg){ | |
console.log('my event emit with arg:',arg); | |
}); | |
obj.on('myevent',function(arg,arg2){ | |
console.log('my event emit with args:',arg,arg2); | |
}); | |
//emit the event | |
obj.emit('myevent','hello','world'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment