summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 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)