Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-10-19 21:57:19 +0300
committerMyles Borins <mylesborins@google.com>2018-11-29 19:39:08 +0300
commit98fc848545942f8a90a214ad2b4544ee9b94d427 (patch)
treea5b8f718f44ac384f5220ecde5e43c1ee4405f51 /doc
parent540168ce57b207b128311b84632c2de96771b135 (diff)
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.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/api/events.md b/doc/api/events.md
index edb4daa2fbc..aafdbcf735b 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)