Descrição do método:
Evento Emit, passando vários parâmetros opcionais para a tabela de parâmetros do ouvinte do evento.
gramática:
A cópia do código é a seguinte:
emissor.emit (evento, [arg1], [arg2], [...])
Receber parâmetros:
Tipo de evento
Parâmetros arg1 ~ argn aprovados (múltiplos)
exemplo:
A cópia do código é a seguinte:
var events = requer ('eventos');
var emissor = new events.EventEmitter ();
emissor.on ('Somevent', função (arg1, arg2) {
console.log ('ouvinte1', arg1, arg2);
})
emissor.on ('Somevent', função (arg1, arg2) {
console.log ('ouvinte2', arg1, arg2);
})
Emissor.emit ('Somevent', 'Byvoid', 1991);
Código -fonte:
A cópia do código é a seguinte:
EventEmitter.prototype.emit = function (type) {
Var Er, Handler, Len, Args, I, ouvintes;
if (! this._events)
this._events = {};
// Se não houver ouvinte de evento 'erro', jogue.
if (type === 'error') {
if (! this._events.error ||
(util.isobject (this._events.error) &&! this._events.error.length)) {
er = argumentos [1];
if (this.Domain) {
if (! er) er = new typeError ('evento não especificado, não especificado "Erro".');
er.domaineMitter = this;
er.Domain = this.Domain;
er.domontrown = false;
this.Domain.emit ('erro', er);
} else if (ere instanceof error) {
jogue er; // Evento de 'erro' não tratado
} outro {
lançar o TypeError ('Evento não especificado, não especificado "Erro".');
}
retornar falso;
}
}
manipulador = this._events [type];
if (util.isundefined (manipulador))
retornar falso;
if (this.Domain && this! == Process)
this.Domain.Enter ();
if (util.isfunction (manipulador)) {
switch (argumentos.length) {
// casos rápidos
Caso 1:
Handler.call (this);
quebrar;
Caso 2:
Handler.Call (isto, argumentos [1]);
quebrar;
Caso 3:
Handler.Call (isto, argumentos [1], argumentos [2]);
quebrar;
// Mais devagar
padrão:
len = argumentos.length;
args = nova matriz (len - 1);
para (i = 1; i <len; i ++)
args [i - 1] = argumentos [i];
Handler.Apply (isto, args);
}
} else if (util.isObject (manipulador)) {
len = argumentos.length;
args = nova matriz (len - 1);
para (i = 1; i <len; i ++)
args [i - 1] = argumentos [i];
ouvintes = handler.slice ();
len = ouvintes.length;
para (i = 0; i <len; i ++)
ouvintes [i] .Apply (isto, args);
}
if (this.Domain && this! == Process)
this.Domain.Exit ();
retornar true;
};