-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Closed
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.
Description
NodeEventTarget:
node/lib/internal/event_target.js
Lines 473 to 479 in 3f4ec9c
removeAllListeners(type) { | |
if (type !== undefined) { | |
this[kEvents].delete(String(type)); | |
} else { | |
this[kEvents].clear(); | |
} | |
} |
Looks like it should return
this
.
EventEmitter:
Lines 515 to 559 in 3f4ec9c
EventEmitter.prototype.removeAllListeners = | |
function removeAllListeners(type) { | |
const events = this._events; | |
if (events === undefined) | |
return this; | |
// Not listening for removeListener, no need to emit | |
if (events.removeListener === undefined) { | |
if (arguments.length === 0) { | |
this._events = ObjectCreate(null); | |
this._eventsCount = 0; | |
} else if (events[type] !== undefined) { | |
if (--this._eventsCount === 0) | |
this._events = ObjectCreate(null); | |
else | |
delete events[type]; | |
} | |
return this; | |
} | |
// Emit removeListener for all listeners on all events | |
if (arguments.length === 0) { | |
for (const key of ReflectOwnKeys(events)) { | |
if (key === 'removeListener') continue; | |
this.removeAllListeners(key); | |
} | |
this.removeAllListeners('removeListener'); | |
this._events = ObjectCreate(null); | |
this._eventsCount = 0; | |
return this; | |
} | |
const listeners = events[type]; | |
if (typeof listeners === 'function') { | |
this.removeListener(type, listeners); | |
} else if (listeners !== undefined) { | |
// LIFO order | |
for (let i = listeners.length - 1; i >= 0; i--) { | |
this.removeListener(type, listeners[i]); | |
} | |
} | |
return this; | |
}; |
Metadata
Metadata
Assignees
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.