Browse Source

events: add type checks to once

Also cleanup unnecessary use of "self" since it will always be called
using .apply() from emit.
v0.9.12-release
Trevor Norris 12 years ago
committed by isaacs
parent
commit
d1b4dcd6ac
  1. 14
      lib/events.js

14
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');
var self = this;
function g() {
self.removeListener(type, g);
this.removeListener(type, g);
listener.apply(this, arguments);
};
}
g.listener = listener;
self.on(type, g);
this.on(type, g);
return this;
};

Loading…
Cancel
Save