new EventEmitter()
Minimal `EventEmitter` interface that is molded against the Node.js
`EventEmitter` interface.
Methods
-
emit(event)
-
Calls each of the listeners registered for a given event.
Parameters:
Name Type Description event
String | Symbol The event name. Returns:
`true` if the event had listeners, else `false`.- Type
- Boolean
-
eventNames()
-
Return an array listing the events for which the emitter has registered listeners.
Returns:
- Type
- Array
-
listenerCount(event)
-
Return the number of listeners listening to a given event.
Parameters:
Name Type Description event
String | Symbol The event name. Returns:
The number of listeners.- Type
- Number
-
listeners(event)
-
Return the listeners registered for a given event.
Parameters:
Name Type Description event
String | Symbol The event name. Returns:
The registered listeners.- Type
- Array
-
on(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description event
String | Symbol The event name. fn
function The listener function. context
* <optional>
this The context to invoke the listener with. Returns:
`this`.- Type
- EventEmitter
-
once(event, fn [, context])
-
Add a one-time listener for a given event.
Parameters:
Name Type Argument Default Description event
String | Symbol The event name. fn
function The listener function. context
* <optional>
this The context to invoke the listener with. Returns:
`this`.- Type
- EventEmitter
-
removeAllListeners( [event])
-
Remove all listeners, or those of the specified event.
Parameters:
Name Type Argument Description event
String | Symbol <optional>
The event name. Returns:
`this`.- Type
- EventEmitter
-
removeListener(event, fn, context, once)
-
Remove the listeners of a given event.
Parameters:
Name Type Description event
String | Symbol The event name. fn
function Only remove the listeners that match this function. context
* Only remove the listeners that have this context. once
Boolean Only remove one-time listeners. Returns:
`this`.- Type
- EventEmitter