Listener
The Listener class represents a single event listener object. Such objects keep all relevant
contextual information such as the event being listened to, the object the listener was attached
to, the callback function and so on.
Constructorโ
Creates a new Listener object
Parameters
new Listener(event, target, callback, [options])
| Parameter | Type | Default | Description |
|---|---|---|---|
event | string Symbol | The event being listened to | |
target | EventEmitter | The EventEmitter object that the listener is attached to. | |
callback | EventEmitter~callback | The function to call when the listener is triggered | |
[options] | Object | {} | |
[options.context] | Object | target | The context to invoke the listener in (a.k.a. the value of this inside the callback function). |
[options.remaining] | number | Infinity | The remaining number of times after which the callback should automatically be removed. |
[options.arguments] | array | An array of arguments that will be passed separately to the callback function upon execution. The array is stored in the arguments property and can be retrieved or modified as desired. |
Throws:
TypeError: The `event` parameter must be a string or `EventEmitter.ANY_EVENT`.ReferenceError: The `target` parameter is mandatory.TypeError: The `callback` must be a function.
Propertiesโ
.argumentsโ
Type: array
An array of arguments to pass to the callback function upon execution.
.callbackโ
Type: function
The callback function to execute.
.contextโ
Type: Object
The context to execute the callback function in (a.k.a. the value of this inside the
callback function)
.countโ
Type: number
The number of times the listener function was executed.
.eventโ
Type: string
The event name.
.remainingโ
Type: number
The remaining number of times after which the callback should automatically be removed.
.suspendedโ
Type: boolean
Whether this listener is currently suspended or not.
.targetโ
Type: EventEmitter
The object that the event is attached to (or that emitted the event).
Methodsโ
.remove()โ
Removes the listener from its target.