Created
March 21, 2012 03:30
-
-
Save nakamura-to/2144051 to your computer and use it in GitHub Desktop.
Event emittable function
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 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