File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Open diff view settings
Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ is opened. All objects which emit events are instances of `events.EventEmitter`.
1010You can access this module by doing: ` require("events"); `
1111
1212Typically, event names are represented by a camel-cased string, however,
13- there aren't any strict restrictions on that, as any string will be accepted.
13+ there aren't any strict restrictions on that, as any valid property key will be
14+ accepted.
1415
1516Functions can then be attached to objects, to be executed when an event
1617is emitted. These functions are called _ listeners_ . Inside a listener
@@ -59,7 +60,7 @@ Returns the number of listeners for a given event.
5960
6061### Event: 'newListener'
6162
62- * ` event ` {String} The event name
63+ * ` event ` {String|Symbol } The event name
6364* ` listener ` {Function} The event handler function
6465
6566This event is emitted * before* a listener is added. When this event is
7071
7172### Event: 'removeListener'
7273
73- * ` event ` {String} The event name
74+ * ` event ` {String|Symbol } The event name
7475* ` listener ` {Function} The event handler function
7576
7677This event is emitted * after* a listener is removed. When this event is
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+ const EventEmitter = require ( 'events' ) ;
5+ const assert = require ( 'assert' ) ;
6+
7+ const ee = new EventEmitter ( ) ;
8+ const foo = Symbol ( 'foo' ) ;
9+ const listener = common . mustCall ( function ( ) { } ) ;
10+
11+ ee . on ( foo , listener ) ;
12+ assert . deepEqual ( ee . listeners ( foo ) , [ listener ] ) ;
13+
14+ ee . emit ( foo ) ;
15+
16+ ee . removeAllListeners ( ) ;
17+ assert . deepEqual ( ee . listeners ( foo ) , [ ] ) ;
18+
19+ ee . on ( foo , listener ) ;
20+ assert . deepEqual ( ee . listeners ( foo ) , [ listener ] ) ;
21+
22+ ee . removeListener ( foo , listener ) ;
23+ assert . deepEqual ( ee . listeners ( foo ) , [ ] ) ;
You can’t perform that action at this time.
0 commit comments