- Introduction
- Web IDL
- Class: EventEmitter
- EventEmitter.on(event, listener)
- EventEmitter.addListener(event, listener)
- EventEmitter.emit(event, [args...])
- EventEmitter.removeListener(event, listener)
- EventEmitter.removeAllListeners(event)
- EventEmitter.eventNames()
- EventEmitter.getMaxListeners()
- EventEmitter.listeners(event)
- EventEmitter.setMaxListeners(max)
- Sample Apps
ZJS provides event APIs that match Node.js
Event
s. We describe
them here as there could be minor differences.
This IDL provides an overview of the interface; see below for documentation of specific API functions. We also have a short document explaining ZJS WebIDL conventions.
Click to show/hide WebIDL
callback ListenerCallback = void (any... params);interface EventEmitter { this on(string event, ListenerCallback listener); this addListener(string event, ListenerCallback listener); boolean emit(string event, any... args); this removeListener(string event, ListenerCallback listener); this removeAllListeners(string event); sequence < string > eventNames(); long getMaxListeners(); sequence < ListenerCallback > listeners(string event); this setMaxListeners(long max); };
event
string The name of the event that you are adding a listener to.listener
ListenerCallback The function that you wish to be called when this event is emitted/triggered.- Returns:
this
so calls can be chained.
Add an event listener function.
event
string The name of the event that you are adding a listener to.listener
ListenerCallback The function that you wish to be called when this event is emitted/triggered.- Returns:
this
so calls can be chained.
Same as EventEmitter.on()
.
event
string The name of the event that you want to emit.args
optional All other arguments will be given to any registered listener functions.- Returns: true if there were any listener functions called.
Triggers an event. Any listener functions that have been added to the event emitter under the event name will be called.
event
string The name of the event you are removing the listener from.listener
ListenerCallback The function you want to remove as a listener.- Returns:
this
so calls can be chained.
Removes a listener function from an event.
event
string The name of the event from which to remove all listeners.- Returns:
this
so calls can be chained.
Removes all listeners from an event
- Returns: an array of strings that correspond to any events. Will return undefined if there are no event's or event listeners for this event emitter.
Get a list of event names from an event emitter object.
- Returns: the maximum number of listeners allowed.
Get the maximum number of listeners allowed for this event emitter object.
event
string The name of the event from which to retrieve the listerners.- Returns: an array of functions that correspond to the
ListenerCallbacks
for the event specified.
Get a list of listeners for an event.
max
long The number of listeners the event emitter can have.- Returns:
this
, so calls can be chained.
Set the max number of listeners for an event emitter object