Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Created March 21, 2012 03:30
Show Gist options
  • Save nakamura-to/2144051 to your computer and use it in GitHub Desktop.
Save nakamura-to/2144051 to your computer and use it in GitHub Desktop.
Event emittable function
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var F = function () {};
util.inherits(F, EventEmitter);
Object.getOwnPropertyNames(Function.prototype).forEach(function(e) {
F.prototype[e] = Function.prototype[e];
});
var f = function () {
console.log('called. args:', Array.prototype.slice.call(arguments));
f.emit('hoge');
};
f.__proto__ = new F();
f.on('hoge', function () {
console.log('emitted.');
})(1, 'a', true);
// called. args: [ 1, 'a', true ]
// emitted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment