-
Notifications
You must be signed in to change notification settings - Fork 388
EventEmitter.eachListener
Passes every listener for a specified event to a function one at a time.
Warning: The plain function is not passed to your callback, an instance of the Event class is. This class is not documented here but helps the internal code manage events. You can find it in the source if you wish to know more. You can find the plain function in the listener variable of the passed object. See the example if you do not understand.
- String type Event type name
- Function callback Function to pass each listener to
Object The current EventEmitter instance to allow chaining
Please bear in mind that this method is not part of the node API. It is mainly used for internal code. If you use it then it will make porting to the node environment more difficult. You can alternatively use EventEmitter.listeners to get an array of listeners to loop over them manually.
var ee = new EventEmitter();
ee.on('foo', function() {
return 'bar';
});
ee.eachListener('foo', function(event) {
console.log(event.listener()); // The actual function is held in Event.listener
// The plain function is not passed, an Event instance is
// The Event instance encapsulates the listener
});