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

EventEmitter.once

Wolfy87 edited this page Nov 4, 2011 · 1 revision

About

Alias of EventEmitter.addEventListener. Works exactly the same but will always pass true for the last argument which causes the event to only run once.

After it has been emitted it removes its self automatically.

Arguments

EventEmitter.once(type, listener, scope);

  • 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

Returns

Object The current EventEmitter instance to allow chaining

Notes

You can get the same effect with EventEmitter.addListener by passing true as the fourth argument, but I would advise against it. The node API does not allow this fourth argument therefor it is mainly for internal use. Use this method to make your code more portable.

Examples

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