Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

EventEmitter.eachListener

Wolfy87 edited this page Nov 4, 2011 · 1 revision

About

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.

Arguments

EventEmitter.eachListener(type, callback);

  • String type Event type name
  • Function callback Function to pass each listener to

Returns

Object The current EventEmitter instance to allow chaining

Notes

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.

Examples

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
});