Browse Source

events: speed up .removeAllListeners()

v0.9.3-release
Ben Noordhuis 13 years ago
parent
commit
56668f54d1
  1. 11
      lib/events.js

11
lib/events.js

@ -239,6 +239,17 @@ EventEmitter.prototype.removeListener = function(type, listener) {
EventEmitter.prototype.removeAllListeners = function(type) {
if (!this._events) return this;
// fast path
if (!this._events.removeListener) {
if (arguments.length === 0) {
this._events = {};
} else if (type && this._events && this._events[type]) {
this._events[type] = null;
}
return this;
}
// slow(ish) path, emit 'removeListener' events for all removals
if (arguments.length === 0) {
for (var key in this._events) {
if (key === 'removeListener') continue;

Loading…
Cancel
Save