Descripción del método:
Elimina un oyente para el evento especificado.
gramática:
La copia del código es la siguiente:
emitter.removelistener (evento, oyente)
Recibir parámetros:
Tipo de evento de evento (cadena)
oyente (función) oyente registrado
ejemplo:
La copia del código es la siguiente:
VAR Callback = function (stream) {
console.log ('¡Alguien conectado!');
};
servidor.on ('conexión', devolución de llamada);
// ...
servidor.removelistener ('conexión', devolución de llamada);
Código fuente:
La copia del código es la siguiente:
// emite un evento 'removeListener' si se eliminó el oyente
EventEmitter.prototype.removelistener = function (type, oyente) {
lista var, posición, longitud, i;
if (! util.Isfunction (oyente))
arrojar typeError ('El oyente debe ser una función');
if (! this._events ||! this._events [tipo])
devolver esto;
list = this._events [type];
longitud = list.length;
posición = -1;
if (list === oyente ||
(Util.isfunction (list.listener) && list.listener === oyente)) {
eliminar esto._events [type];
if (this._events.removelistener)
this.emit ('removeListener', type, oyente);
} else if (util.isobject (list)) {
para (i = longitud; i--> 0;) {
if (list [i] === oyente ||
(lista [i] .listener && list [i] .listener === oyente)) {
posición = i;
romper;
}
}
if (posición <0)
devolver esto;
if (list.length === 1) {
list.length = 0;
eliminar esto._events [type];
} demás {
list.splice (posición, 1);
}
if (this._events.removelistener)
this.emit ('removeListener', type, oyente);
}
devolver esto;
};