Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 84fdb1c

Browse filesBrowse files
jasnelltargos
authored andcommitted
doc: add note about removeListener order
Fixes: #21635 PR-URL: #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>
1 parent f4c4b2b commit 84fdb1c
Copy full SHA for 84fdb1c

File tree

Expand file treeCollapse file tree

1 file changed

+20
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/events.md‎

Copy file name to clipboardExpand all lines: doc/api/events.md
+20Lines changed: 20 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,26 @@ being removed. This will not impact the order in which listeners are called,
581581
but it means that any copies of the listener array as returned by
582582
the `emitter.listeners()` method will need to be recreated.
583583

584+
When a single function has been added as a handler multiple times for a single
585+
event (as in the example below), `removeListener()` will remove the most
586+
recently added instance. In the example the `once('ping')`
587+
listener is removed:
588+
589+
```js
590+
const ee = new EventEmitter();
591+
592+
function pong() {
593+
console.log('pong');
594+
}
595+
596+
ee.on('ping', pong);
597+
ee.once('ping', pong);
598+
ee.removeListener('ping', pong);
599+
600+
ee.emit('ping');
601+
ee.emit('ping');
602+
```
603+
584604
Returns a reference to the `EventEmitter`, so that calls can be chained.
585605

586606
### emitter.setMaxListeners(n)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.