Class EventEmitter

When an EventEmitter instance experiences an error, the typical action is to emit an ‘error’ event. Error events are treated as a special case in node. If there is no listener for it, then the default action is to print a stack trace and exit the program. All EventEmitters emit the event ‘newListener’ when new listeners are added.

Constructor

class EventEmitter()

Methods

addListener

EventEmitter#addListener(type, listener)
Arguments:
  • type (String) – The event name
  • listener (Function) – The listener function
Returns EventEmitter:
 

Adds a listener to the end of the listeners array for the specified event.

emit

EventEmitter#emit(event[, arg, arg2])
Arguments:
  • event (String) – The event name
  • arg,arg2 – The arguments to pass

Execute each of the listeners in order with the supplied arguments.

listeners

EventEmitter#listeners(type)
Arguments:
  • type (String) – The event name
Returns EventEmitter:
 

Instance

Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners.

on

EventEmitter#on()

See also

EventEmitter#addListener

once

EventEmitter#once(type, listener)
Arguments:
  • type (String) – The event name
  • listener (Function) – The listener function
Returns EventEmitter:
 

Instance

Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed.

removeAllListeners

EventEmitter#removeAllListeners(type)
Arguments:
  • type (String) – The event name
Returns EventEmitter:
 

Instance

Removes all listeners, or those of the specified event.

removeListener

EventEmitter#removeListener(type, listener)
Arguments:
  • type (String) – The event name
  • listener (Function) – The listener function
Returns EventEmitter:
 

Instance

Remove a listener from the listener array for the specified event. Caution: changes array indices in the listener array behind the listener.

setMaxListeners

EventEmitter#setMaxListeners(n)
Arguments:
  • n (Number) –

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This function allows that to be increased. Set to zero for unlimited.

Table Of Contents

Previous topic

Class CssRenderer

Next topic

Class FlowLayout