Methods
emit(event) → {Boolean}
Calls each of the listeners registered for a given event.
Parameters:
Name | Type | Description |
---|---|---|
event |
String
|
Symbol
|
The event name. |
Returns:
- Type:
-
Boolean
true
if the event had listeners, else false
.
eventNames() → {Array}
Return an array listing the events for which the emitter has registered listeners.
Returns:
- Type:
-
Array
listenerCount(event) → {Number}
Return the number of listeners listening to a given event.
Parameters:
Name | Type | Description |
---|---|---|
event |
String
|
Symbol
|
The event name. |
Returns:
- Type:
-
Number
The number of listeners.
listeners(event) → {Array}
Return the listeners registered for a given event.
Parameters:
Name | Type | Description |
---|---|---|
event |
String
|
Symbol
|
The event name. |
Returns:
- Type:
-
Array
The registered listeners.
on(event, fn, contextopt) → {EventEmitter}
Add a listener for a given event.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
String
|
Symbol
|
The event name. |
||
fn |
function
|
The listener function. |
||
context |
*
|
<optional> |
this |
The context to invoke the listener with. |
Returns:
- Type:
-
EventEmitter
this
.
once(event, fn, contextopt) → {EventEmitter}
Add a one-time listener for a given event.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
String
|
Symbol
|
The event name. |
||
fn |
function
|
The listener function. |
||
context |
*
|
<optional> |
this |
The context to invoke the listener with. |
Returns:
- Type:
-
EventEmitter
this
.
removeAllListeners(eventopt) → {EventEmitter}
Remove all listeners, or those of the specified event.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event |
String
|
Symbol
|
<optional> |
The event name. |
Returns:
- Type:
-
EventEmitter
this
.
removeListener(event, fn, context, once) → {EventEmitter}
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:
- Type:
-
EventEmitter
this
.