EventEmitter#once only takes instanceof function

v0.7.4-release
Aaron Heckmann 2011-03-15 09:01:24 -04:00 committed by Ryan Dahl
parent 52b9ede6db
commit a4dad95be3
1 changed files with 4 additions and 0 deletions

View File

@ -137,6 +137,10 @@ EventEmitter.prototype.addListener = function(type, listener) {
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if ('function' !== typeof listener) {
throw new Error('.once only takes instances of Function');
}
var self = this;
self.on(type, function g() {
self.removeListener(type, g);