Created
November 27, 2011 04:46
-
-
Save xiaojue/1396974 to your computer and use it in GitHub Desktop.
nodejs 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 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