Skip to content

Instantly share code, notes, and snippets.

@xiaojue
Created November 27, 2011 04:46
Show Gist options
  • Save xiaojue/1396974 to your computer and use it in GitHub Desktop.
Save xiaojue/1396974 to your computer and use it in GitHub Desktop.
nodejs events
var events=require('events').EventEmitter;
var test=function(){
events.call(this);
}
test.prototype=Object.create(events.prototype,{
constructor:{
value:test,
enumerable:false
},
run:{
value:function(n){
var that=this;
for(var i=0;i<n;i++){
console.log(i);
if(i===5){
that.emit('five');
}
}
}
}
});
var myeventTest=new test();
myeventTest.on('five',function(){
console.log('fired five event');
});
myeventTest.run(8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment