mirror of https://github.com/nodejs/node.git
doc: fix EventEmitter examples
Since the section refers to EventEmitter, instances in the example should be created of the same class EventEmitter. PR-URL: https://github.com/nodejs/node/pull/33513 Reviewed-By: James M Snell <jasnell@gmail.com>pull/35522/head
parent
7f25fe8b67
commit
9e5a27a9d3
|
@ -268,6 +268,8 @@ but important side effect: any *additional* listeners registered to the same
|
|||
listener that is in the process of being added.
|
||||
|
||||
```js
|
||||
class MyEmitter extends EventEmitter {}
|
||||
|
||||
const myEmitter = new MyEmitter();
|
||||
// Only do this once so we don't loop forever
|
||||
myEmitter.once('newListener', (event, listener) => {
|
||||
|
@ -319,7 +321,7 @@ A class method that returns the number of listeners for the given `eventName`
|
|||
registered on the given `emitter`.
|
||||
|
||||
```js
|
||||
const myEmitter = new MyEmitter();
|
||||
const myEmitter = new EventEmitter();
|
||||
myEmitter.on('event', () => {});
|
||||
myEmitter.on('event', () => {});
|
||||
console.log(EventEmitter.listenerCount(myEmitter, 'event'));
|
||||
|
|
Loading…
Reference in New Issue