diff options
author | James M Snell <jasnell@gmail.com> | 2018-10-19 11:57:19 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-10-23 13:12:03 -0700 |
commit | b049d55cd882a9d3e8a2f5be69dd9fdb6623eab7 (patch) | |
tree | 72fdd8463ce0280b04cd141979db1d47f7a9592f /doc | |
parent | 6c079905a3dc4a6e3317b4fa1ada0ce39c8d0db7 (diff) | |
download | android-node-v8-b049d55cd882a9d3e8a2f5be69dd9fdb6623eab7.tar.gz android-node-v8-b049d55cd882a9d3e8a2f5be69dd9fdb6623eab7.tar.bz2 android-node-v8-b049d55cd882a9d3e8a2f5be69dd9fdb6623eab7.zip |
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>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/events.md | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/api/events.md b/doc/api/events.md index edb4daa2fb..aafdbcf735 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -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) |