Created
December 4, 2013 16:18
-
-
Save booxood/7790401 to your computer and use it in GitHub Desktop.
node.js EventEmitter
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 util = require('util'); | |
var event = require('events').EventEmitter; | |
function f(){ | |
// event.call(this); | |
} | |
// util.inherits(f, event); | |
f.prototype = new event(); | |
var ff = new f(); | |
ff.on('do', function(str){ | |
console.log('1 :' + str); | |
}); | |
ff.once('do', function(str){ | |
console.log('2 :' + str); | |
}); | |
[1,2,3].forEach(function(v, i){ | |
ff.emit('do', v); | |
}); | |
//console | |
1 :1 | |
2 :1 | |
1 :2 | |
1 :3 | |
[Finished in 0.2s] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment