diff --git a/lib/events.js b/lib/events.js index d9e09bbc928..4cfa7407656 100644 --- a/lib/events.js +++ b/lib/events.js @@ -165,18 +165,18 @@ EventEmitter.prototype.addListener = function(type, listener) { EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { - if ('function' !== typeof listener) { - throw TypeError('.once only takes instances of Function'); + if (typeof type !== 'string') + throw TypeError('type must be a string'); + if (typeof listener !== 'function') + throw TypeError('listener must be a function'); + + function g() { + this.removeListener(type, g); + listener.apply(this, arguments); } - var self = this; - function g() { - self.removeListener(type, g); - listener.apply(this, arguments); - }; - g.listener = listener; - self.on(type, g); + this.on(type, g); return this; };