Skip to content

Commit 100af7f

Browse files
doc,test: remove usage of util.inherits
1 parent fb6b83c commit 100af7f

File tree

2 files changed

+31
-53
lines changed

2 files changed

+31
-53
lines changed

doc/api/stream.md

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,7 @@ changes:
37223722

37233723
<!-- eslint-disable no-useless-constructor -->
37243724

3725-
```js
3725+
```cjs
37263726
const { Writable } = require('node:stream');
37273727

37283728
class MyWritable extends Writable {
@@ -3734,18 +3734,18 @@ class MyWritable extends Writable {
37343734
}
37353735
```
37363736

3737-
Or, when using pre-ES6 style constructors:
3737+
<!-- eslint-disable no-useless-constructor -->
37383738

3739-
```js
3740-
const { Writable } = require('node:stream');
3741-
const util = require('node:util');
3739+
```mjs
3740+
import { Writable } from 'node:stream';
37423741

3743-
function MyWritable(options) {
3744-
if (!(this instanceof MyWritable))
3745-
return new MyWritable(options);
3746-
Writable.call(this, options);
3742+
class MyWritable extends Writable {
3743+
constructor(options) {
3744+
// Calls the stream.Writable() constructor.
3745+
super(options);
3746+
// ...
3747+
}
37473748
}
3748-
util.inherits(MyWritable, Writable);
37493749
```
37503750

37513751
Or, using the simplified constructor approach:
@@ -4095,20 +4095,6 @@ class MyReadable extends Readable {
40954095
}
40964096
```
40974097
4098-
Or, when using pre-ES6 style constructors:
4099-
4100-
```js
4101-
const { Readable } = require('node:stream');
4102-
const util = require('node:util');
4103-
4104-
function MyReadable(options) {
4105-
if (!(this instanceof MyReadable))
4106-
return new MyReadable(options);
4107-
Readable.call(this, options);
4108-
}
4109-
util.inherits(MyReadable, Readable);
4110-
```
4111-
41124098
Or, using the simplified constructor approach:
41134099
41144100
```js
@@ -4427,7 +4413,7 @@ changes:
44274413
44284414
<!-- eslint-disable no-useless-constructor -->
44294415
4430-
```js
4416+
```cjs
44314417
const { Duplex } = require('node:stream');
44324418

44334419
class MyDuplex extends Duplex {
@@ -4438,18 +4424,17 @@ class MyDuplex extends Duplex {
44384424
}
44394425
```
44404426
4441-
Or, when using pre-ES6 style constructors:
4427+
<!-- eslint-disable no-useless-constructor -->
44424428
4443-
```js
4444-
const { Duplex } = require('node:stream');
4445-
const util = require('node:util');
4429+
```mjs
4430+
import { Duplex } from 'node:stream';
44464431

4447-
function MyDuplex(options) {
4448-
if (!(this instanceof MyDuplex))
4449-
return new MyDuplex(options);
4450-
Duplex.call(this, options);
4432+
class MyDuplex extends Duplex {
4433+
constructor(options) {
4434+
super(options);
4435+
// ...
4436+
}
44514437
}
4452-
util.inherits(MyDuplex, Duplex);
44534438
```
44544439
44554440
Or, using the simplified constructor approach:
@@ -4624,7 +4609,7 @@ output on the `Readable` side is not consumed.
46244609
46254610
<!-- eslint-disable no-useless-constructor -->
46264611
4627-
```js
4612+
```cjs
46284613
const { Transform } = require('node:stream');
46294614

46304615
class MyTransform extends Transform {
@@ -4635,18 +4620,17 @@ class MyTransform extends Transform {
46354620
}
46364621
```
46374622
4638-
Or, when using pre-ES6 style constructors:
4623+
<!-- eslint-disable no-useless-constructor -->
46394624
4640-
```js
4641-
const { Transform } = require('node:stream');
4642-
const util = require('node:util');
4625+
```mjs
4626+
import { Transform } from 'node:stream';
46434627

4644-
function MyTransform(options) {
4645-
if (!(this instanceof MyTransform))
4646-
return new MyTransform(options);
4647-
Transform.call(this, options);
4628+
class MyTransform extends Transform {
4629+
constructor(options) {
4630+
super(options);
4631+
// ...
4632+
}
46484633
}
4649-
util.inherits(MyTransform, Transform);
46504634
```
46514635
46524636
Or, using the simplified constructor approach:

test/parallel/test-event-capture-rejections.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const { EventEmitter, captureRejectionSymbol } = require('events');
5-
const { inherits } = require('util');
6-
7-
// Inherits from EE without a call to the
8-
// parent constructor.
9-
function NoConstructor() {
10-
}
3+
const assert = require('node:assert');
4+
const { EventEmitter, captureRejectionSymbol } = require('node:events');
115

126
// captureRejections param validation
137
{
@@ -24,7 +18,7 @@ function NoConstructor() {
2418
});
2519
}
2620

27-
inherits(NoConstructor, EventEmitter);
21+
class NoConstructor extends EventEmitter {}
2822

2923
function captureRejections() {
3024
const ee = new EventEmitter({ captureRejections: true });

0 commit comments

Comments
 (0)