Skip to content

Commit 84ab100

Browse files
louwersTrott
andauthored
Remove call to deprecated function util.inherits (#4483)
* Remove call to deprecated function util.inherits * Update event-loop-timers-and-nexttick.md Co-authored-by: Rich Trott <[email protected]>
1 parent 0c7d743 commit 84ab100

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

locale/en/docs/guides/event-loop-timers-and-nexttick.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,19 +444,18 @@ the event loop to proceed, it must hit the **poll** phase, which means
444444
there is a non-zero chance that a connection could have been received
445445
allowing the connection event to be fired before the listening event.
446446

447-
Another example is running a function constructor that was to, say,
448-
inherit from `EventEmitter` and it wanted to call an event within the
449-
constructor:
447+
Another example is inheriting from `EventEmitter` and emitting an
448+
event from within the constructor:
450449

451450
```js
452451
const EventEmitter = require('events');
453-
const util = require('util');
454452

455-
function MyEmitter() {
456-
EventEmitter.call(this);
457-
this.emit('event');
453+
class MyEmitter extends EventEmitter {
454+
constructor() {
455+
super();
456+
this.emit('event');
457+
}
458458
}
459-
util.inherits(MyEmitter, EventEmitter);
460459

461460
const myEmitter = new MyEmitter();
462461
myEmitter.on('event', () => {
@@ -472,17 +471,17 @@ after the constructor has finished, which provides the expected results:
472471

473472
```js
474473
const EventEmitter = require('events');
475-
const util = require('util');
476474

477-
function MyEmitter() {
478-
EventEmitter.call(this);
475+
class MyEmitter extends EventEmitter {
476+
constructor() {
477+
super();
479478

480-
// use nextTick to emit the event once a handler is assigned
481-
process.nextTick(() => {
482-
this.emit('event');
483-
});
479+
// use nextTick to emit the event once a handler is assigned
480+
process.nextTick(() => {
481+
this.emit('event');
482+
});
483+
}
484484
}
485-
util.inherits(MyEmitter, EventEmitter);
486485

487486
const myEmitter = new MyEmitter();
488487
myEmitter.on('event', () => {

0 commit comments

Comments
 (0)