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.