File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines 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)
You can’t perform that action at this time.
0 commit comments