Differences between Event Emitter and Event Target
Event Emitter (preferred for use)
Taken from the events module
Multiple listeners per event
Fully emulates the Event Emitter from the browser
Error handling via error
Built-in events add / remove listeners
Event Target
Global variable
Only 1 listener per event
Partially emulates the browser API
No handling via error
No events add and remove listeners
Event Target “addEventListener”
Add handler
Event Target “dispatchEvent”
Execute an event, but the argument must be new Event(“name”), not just a string
Event Emitter “addListener”
Subscribe to event
Event Emitter “on”
Subscribe to event (same as addListener)
Event Emitter “removeListener”
Unsubscribe from event
Event Emitter “off”
Unsubscribe from event (same as removeListener)
Event Emitter “prependListener”
Will add the listener to the beginning of the emitter queue, and its event will be executed before all others (by default, it is executed in the order of the adding queue)
Event Emitter “prependOnceListener”
Same as prependListener, but after execution removes the listener from the emitter
Event Emitter “removeAllListeners”
Unsubscribe from all listeners
Event Emitter “emit”
Execute event
Event Emitter “once”
After the first execution the event will be removed from the emitter
Event Emitter “setMaxListeners”
Sets the maximum number of listeners for the emitter, by default there are 10
Event Emitter “listenerCount”
Find out how many listeners are at one event
Event Emitter “eventNames”
Shows the names of events that are currently attached to the emitter
Event Emitter “listeners”
Shows which functions are hanging on the event