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 @@ -581,6 +581,26 @@ being removed. This will not impact the order in which listeners are called,
581581but it means that any copies of the listener array as returned by
582582the ` 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+ 
584604Returns a reference to the ` EventEmitter ` , so that calls can be chained.
585605
586606### emitter.setMaxListeners(n)  
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments