Skip to content

Commit

Permalink
doc: add note about removeListener order
Browse files Browse the repository at this point in the history
Fixes: nodejs#21635

PR-URL: nodejs#23762
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
jasnell committed Oct 23, 2018
1 parent 6c07990 commit b049d55
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b049d55

Please sign in to comment.