Listeners listen only to normal JS functions. Thus, you can pass as many arguments as you want, but the function can only access the arguments that you specified in the definition of the function ie
var EE = require('events').EventEmitter; var ee = new EE(); ee.on('test', function (first, second, third) { console.log(first, second, third); //Will output full phrase }); ee.on('test', function (first) { console.log(first); //Will output just first word }); ee.on('test', function () { console.log.apply(console, arguments); //Will output full phrase again }); ee.emit('test', 'Hello', 'my', 'world!');
In fact, you can see that all the arguments provided are always passed to each function. But if you do not specify the argument names in the function declaration, you cannot directly access these arguments. But you can use the magic argument in each function to access all the arguments provided. Of course, the argument is provided to the function in the order in which they were passed to the EE.
mynameisdaniil
source share