diff --git a/doc/api/events.md b/doc/api/events.md index 8eaa8cae102b75..a24a5efcb20ded 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -557,6 +557,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)