EventEmitter Class
The following describes the properties and methods of the EventEmitter class. The EventEmitter class is a base class for creating event-driven applications. It works by managing the following event object during each event loop.
❐ Copy
after
Sets a hook function that will be called after each event handler is called. This is useful for analytical purposes.
❐ Copy
before
Sets a hook function that will be called before each event handler is called. This is useful for analytical purposes.
❐ Copy
The callback takes in an argument same as the method.
event
Returns the event object of the current event being emitted. You can only really access this object in an event handler or one of the event hooks.
❐ Copy
WARNING: Event objects are short lived. Meaning they only exist during the event loop. If you need to store them, you should copy them to a new object.
listeners
Returns a read-only shallow copy of the listeners. Listeners are organized by events and events can have multiple listeners and listeners have priorities. The listeners are not pre-organized by priority. This happens during the event loop.
❐ Copy
clear()
Removes an event and all its actions from the .
Usage
❐ Copy
Example
❐ Copy
emit()
Calls all the callbacks of the given event passing the given arguments.
Usage
❐ Copy
Example
❐ Copy
match()
Compares the given event with the event in the . Returns a of all possible event matches.
Usage
❐ Copy
Example
❐ Copy
on()
Adds an action callback to the given event listener.
Usage
❐ Copy
Example
❐ Copy
tasks()
Sorts all the action callbacks by priority and returns a task queue.
Usage
❐ Copy
Example
❐ Copy
unbind()
Removes an action callback from the given event listener.
Usage
❐ Copy
Example
❐ Copy
use()
Allows events from other emitters to apply here.
Usage
❐ Copy
Example
❐ Copy