Skip to content

Commit

Permalink
Add EventEmitter.removeListener
Browse files Browse the repository at this point in the history
  • Loading branch information
fwg authored and ry committed Nov 13, 2009
1 parent 04f9c9f commit bd6c08a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ server.addListener("connection", function (socket) {
});
----------------------------------------

+emitter.removeListener(event, listener)+ ::
Remove a listener from the listener array for the specified event.
*Caution*: changes array indices in the listener array behind the listener.

+emitter.listeners(event)+ ::
Returns an array of listeners for the specified event. This array can be
Expand Down
11 changes: 11 additions & 0 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ process.EventEmitter.prototype.addListener = function (type, listener) {
return this;
};

process.EventEmitter.prototype.removeListener = function (type, listener) {
if (listener instanceof Function) {
// does not use listeners(), so no side effect of creating _events[type]
if (!this._events || !this._events.hasOwnProperty(type)) return;
var list = this._events[type];
if (list.indexOf(listener) < 0) return;
list.splice(list.indexOf(listener), 1);
}
return this;
};

process.EventEmitter.prototype.listeners = function (type) {
if (!this._events) this._events = {};
if (!this._events.hasOwnProperty(type)) this._events[type] = [];
Expand Down

0 comments on commit bd6c08a

Please sign in to comment.