Method description:
Remove a listener for the specified event.
Grammar:
emitter.removeListener(event, listener)
Receive parameters:
event (string) Event type
listener (function) Registered listener
Example:
var callback = function(stream) {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
Source code:
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!util.isFunction(listener))
Throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
Return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(util.isFunction(list.listener) && list.listener === listener)) {
Delete this._events[type];
If (this._events.removeListener)
This.emit('removeListener', type, listener);
} else if (util.isObject(list)) {
for (i = length; i-- > 0;) {
If (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
If (position < 0)
return this;
If (list.length === 1) {
List.length = 0;
Delete this._events[type];
} else {
List.splice(position, 1);
}
If (this._events.removeListener)
This.emit('removeListener', type, listener);
}
return this;
};