Skip to content

Instantly share code, notes, and snippets.

@booxood
Created December 4, 2013 16:18
Show Gist options
  • Save booxood/7790401 to your computer and use it in GitHub Desktop.
Save booxood/7790401 to your computer and use it in GitHub Desktop.
node.js EventEmitter
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