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

EventEmitter.on

Wolfy87 edited this page Feb 4, 2012 · 2 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.

Alias of the EventEmitter.addListener method.

Arguments

EventEmitter.on(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. This is an alias of EventEmitter.addListener, both behave exactly the same.

Examples

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