@@ -167,6 +167,9 @@ myEmitter.emit('error', new Error('whoops!'));
167
167
```
168
168
169
169
## Class: EventEmitter
170
+ <!-- YAML
171
+ added: v0.1.26
172
+ -->
170
173
171
174
The ` EventEmitter ` class is defined and exposed by the ` events ` module:
172
175
@@ -178,6 +181,9 @@ All EventEmitters emit the event `'newListener'` when new listeners are
178
181
added and ` 'removeListener' ` when existing listeners are removed.
179
182
180
183
### Event: 'newListener'
184
+ <!-- YAML
185
+ added: v0.1.26
186
+ -->
181
187
182
188
* ` eventName ` {String|Symbol} The name of the event being listened for
183
189
* ` listener ` {Function} The event handler function
@@ -214,13 +220,20 @@ myEmitter.emit('event');
214
220
```
215
221
216
222
### Event: 'removeListener'
223
+ <!-- YAML
224
+ added: v0.9.3
225
+ -->
217
226
218
227
* ` eventName ` {String|Symbol} The event name
219
228
* ` listener ` {Function} The event handler function
220
229
221
230
The ` 'removeListener' ` event is emitted * after* the ` listener ` is removed.
222
231
223
232
### EventEmitter.listenerCount(emitter, eventName)
233
+ <!-- YAML
234
+ added: v0.9.12
235
+ deprecated: v4.0.0
236
+ -->
224
237
225
238
> Stability: 0 - Deprecated: Use [ ` emitter.listenerCount() ` ] [ ] instead.
226
239
@@ -236,6 +249,9 @@ console.log(EventEmitter.listenerCount(myEmitter, 'event'));
236
249
```
237
250
238
251
### EventEmitter.defaultMaxListeners
252
+ <!-- YAML
253
+ added: v0.11.2
254
+ -->
239
255
240
256
By default, a maximum of ` 10 ` listeners can be registered for any single
241
257
event. This limit can be changed for individual ` EventEmitter ` instances
@@ -263,10 +279,16 @@ emitter.once('event', () => {
263
279
```
264
280
265
281
### emitter.addListener(eventName, listener)
282
+ <!-- YAML
283
+ added: v0.1.26
284
+ -->
266
285
267
286
Alias for ` emitter.on(eventName, listener) ` .
268
287
269
288
### emitter.emit(eventName[ , arg1] [ , arg2 ] [ , ...] )
289
+ <!-- YAML
290
+ added: v0.1.26
291
+ -->
270
292
271
293
Synchronously calls each of the listeners registered for the event named
272
294
` eventName ` , in the order they were registered, passing the supplied arguments
@@ -275,6 +297,9 @@ to each.
275
297
Returns ` true ` if the event had listeners, ` false ` otherwise.
276
298
277
299
### emitter.eventNames()
300
+ <!-- YAML
301
+ added: v6.0.0
302
+ -->
278
303
279
304
Returns an array listing the events for which the emitter has registered
280
305
listeners. The values in the array will be strings or Symbols.
@@ -293,18 +318,27 @@ console.log(myEE.eventNames());
293
318
```
294
319
295
320
### emitter.getMaxListeners()
321
+ <!-- YAML
322
+ added: v1.0.0
323
+ -->
296
324
297
325
Returns the current max listener value for the ` EventEmitter ` which is either
298
326
set by [ ` emitter.setMaxListeners(n) ` ] [ ] or defaults to
299
327
[ ` EventEmitter.defaultMaxListeners ` ] [ ] .
300
328
301
329
### emitter.listenerCount(eventName)
330
+ <!-- YAML
331
+ added: v3.2.0
332
+ -->
302
333
303
334
* ` eventName ` {String|Symbol} The name of the event being listened for
304
335
305
336
Returns the number of listeners listening to the event named ` eventName ` .
306
337
307
338
### emitter.listeners(eventName)
339
+ <!-- YAML
340
+ added: v0.1.26
341
+ -->
308
342
309
343
Returns a copy of the array of listeners for the event named ` eventName ` .
310
344
@@ -317,6 +351,9 @@ console.log(util.inspect(server.listeners('connection')));
317
351
```
318
352
319
353
### emitter.on(eventName, listener)
354
+ <!-- YAML
355
+ added: v0.1.101
356
+ -->
320
357
321
358
* ` eventName ` {String|Symbol} The name of the event.
322
359
* ` listener ` {Function} The callback function
@@ -350,6 +387,9 @@ myEE.emit('foo');
350
387
```
351
388
352
389
### emitter.once(eventName, listener)
390
+ <!-- YAML
391
+ added: v0.3.0
392
+ -->
353
393
354
394
* ` eventName ` {String|Symbol} The name of the event.
355
395
* ` listener ` {Function} The callback function
@@ -380,6 +420,9 @@ myEE.emit('foo');
380
420
```
381
421
382
422
### emitter.prependListener(eventName, listener)
423
+ <!-- YAML
424
+ added: v6.0.0
425
+ -->
383
426
384
427
* ` eventName ` {String|Symbol} The name of the event.
385
428
* ` listener ` {Function} The callback function
@@ -399,6 +442,9 @@ server.prependListener('connection', (stream) => {
399
442
Returns a reference to the ` EventEmitter ` , so that calls can be chained.
400
443
401
444
### emitter.prependOnceListener(eventName, listener)
445
+ <!-- YAML
446
+ added: v6.0.0
447
+ -->
402
448
403
449
* ` eventName ` {String|Symbol} The name of the event.
404
450
* ` listener ` {Function} The callback function
@@ -416,6 +462,9 @@ server.prependOnceListener('connection', (stream) => {
416
462
Returns a reference to the ` EventEmitter ` , so that calls can be chained.
417
463
418
464
### emitter.removeAllListeners([ eventName] )
465
+ <!-- YAML
466
+ added: v0.1.26
467
+ -->
419
468
420
469
Removes all listeners, or those of the specified ` eventName ` .
421
470
@@ -426,6 +475,9 @@ component or module (e.g. sockets or file streams).
426
475
Returns a reference to the ` EventEmitter ` , so that calls can be chained.
427
476
428
477
### emitter.removeListener(eventName, listener)
478
+ <!-- YAML
479
+ added: v0.1.26
480
+ -->
429
481
430
482
Removes the specified ` listener ` from the listener array for the event named
431
483
` eventName ` .
@@ -490,6 +542,9 @@ the `emitter.listeners()` method will need to be recreated.
490
542
Returns a reference to the ` EventEmitter ` , so that calls can be chained.
491
543
492
544
### emitter.setMaxListeners(n)
545
+ <!-- YAML
546
+ added: v0.3.5
547
+ -->
493
548
494
549
By default EventEmitters will print a warning if more than ` 10 ` listeners are
495
550
added for a particular event. This is a useful default that helps finding
0 commit comments