This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 388
EventEmitter.on
Wolfy87 edited this page Feb 4, 2012
·
2 revisions
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.
- 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
Object The current EventEmitter instance to allow chaining
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.
var ee = new EventEmitter();
ee.on('foo', function() {
console.log('bar');
});