Skip to content

Instantly share code, notes, and snippets.

@kshirish
Last active August 29, 2015 14:15
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 kshirish/86787769c9155dba269e to your computer and use it in GitHub Desktop.
Save kshirish/86787769c9155dba269e to your computer and use it in GitHub Desktop.
node api
var EventEmitter = require('events').EventEmitter
, util = require('util')
;
function Animal(){
this.nose = 2;
this.ear = 4;
}
util.inherits(Animal, EventEmitter);
Animal.prototype.show = function() {
var obj = {
name: 'pai',
age: 21
};
console.log('let me show you something');
this.emit('customEvent',obj);
};
var a = new Animal();
a.on('customEvent', function(x){
console.log(x);
console.log('I caught the custom event');
});
a.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment