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

EventEmitter.addListener

Wolfy87 edited this page Nov 4, 2011 · 7 revisions

About

Adds an event listener for the specified event. When the max listener limit is exceeded you will be presented with a warning in the console, this helps to avoid memory leaks. You can raise the max listener limit with EventEmitter.setMaxListeners.

Arguments

EventEmitter.addListener(type, listener, scope, once);

  • String type Event type name
  • Function listener Function to be called when the event is fired
  • Object scope Object that this should be set to when the listener is called
  • Boolean once If true then the listener will be removed after the first call

Returns

Object The current EventEmitter instance to allow chaining

Notes

The once argument is mainly for internal use. If you wish to create an event that is only run one you should use EventEmitter.once. You can also use the alias of this method, EventEmitter.on.

Examples

var ee = new EventEmitter();
ee.addListener('foo', function() {
    console.log('bar');
});