mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
doc: add note about removeListener order
Fixes: https://github.com/nodejs/node/issues/21635 PR-URL: https://github.com/nodejs/node/pull/23762 Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
@@ -581,6 +581,26 @@ being removed. This will not impact the order in which listeners are called,
|
||||
but it means that any copies of the listener array as returned by
|
||||
the `emitter.listeners()` method will need to be recreated.
|
||||
|
||||
When a single function has been added as a handler multiple times for a single
|
||||
event (as in the example below), `removeListener()` will remove the most
|
||||
recently added instance. In the example the `once('ping')`
|
||||
listener is removed:
|
||||
|
||||
```js
|
||||
const ee = new EventEmitter();
|
||||
|
||||
function pong() {
|
||||
console.log('pong');
|
||||
}
|
||||
|
||||
ee.on('ping', pong);
|
||||
ee.once('ping', pong);
|
||||
ee.removeListener('ping', pong);
|
||||
|
||||
ee.emit('ping');
|
||||
ee.emit('ping');
|
||||
```
|
||||
|
||||
Returns a reference to the `EventEmitter`, so that calls can be chained.
|
||||
|
||||
### emitter.setMaxListeners(n)
|
||||
|
||||
Reference in New Issue
Block a user