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.