Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
Created October 30, 2012 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizanRahman/3979874 to your computer and use it in GitHub Desktop.
Save mizanRahman/3979874 to your computer and use it in GitHub Desktop.
Play with node.js events. Make your own events.
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