| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0ff88a3 commit e5f75cf
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -557,6 +557,26 @@ being removed. This will not impact the order in which listeners are called, | |||
| 557 | 557 | but it means that any copies of the listener array as returned by | |
| 558 | 558 | the `emitter.listeners()` method will need to be recreated. | |
| 559 | 559 | ||
| 560 | + When a single function has been added as a handler multiple times for a single | ||
| 561 | + event (as in the example below), `removeListener()` will remove the most | ||
| 562 | + recently added instance. In the example the `once('ping')` | ||
| 563 | + listener is removed: | ||
| 564 | + | ||
| 565 | + ```js | ||
| 566 | + const ee = new EventEmitter(); | ||
| 567 | + | ||
| 568 | + function pong() { | ||
| 569 | + console.log('pong'); | ||
| 570 | + } | ||
| 571 | + | ||
| 572 | + ee.on('ping', pong); | ||
| 573 | + ee.once('ping', pong); | ||
| 574 | + ee.removeListener('ping', pong); | ||
| 575 | + | ||
| 576 | + ee.emit('ping'); | ||
| 577 | + ee.emit('ping'); | ||
| 578 | + ``` | ||
| 579 | + | ||
| 560 | 580 | Returns a reference to the `EventEmitter`, so that calls can be chained. | |
| 561 | 581 | ||
| 562 | 582 | ### emitter.setMaxListeners(n) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments