Skip to content

Commit e43bedc

Browse files
doc: remove usage of util.inherits
Signed-off-by: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> PR-URL: #60817 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 8fc7341 commit e43bedc

1 file changed

Lines changed: 28 additions & 44 deletions

File tree

doc/api/stream.md

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

38223822
<!-- eslint-disable no-useless-constructor -->
38233823

3824-
```js
3824+
```cjs
38253825
const { Writable } = require('node:stream');
38263826

38273827
class MyWritable extends Writable {
@@ -3833,18 +3833,18 @@ class MyWritable extends Writable {
38333833
}
38343834
```
38353835

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

3838-
```js
3839-
const { Writable } = require('node:stream');
3840-
const util = require('node:util');
3838+
```mjs
3839+
import { Writable } from 'node:stream';
38413840

3842-
function MyWritable(options) {
3843-
if (!(this instanceof MyWritable))
3844-
return new MyWritable(options);
3845-
Writable.call(this, options);
3841+
class MyWritable extends Writable {
3842+
constructor(options) {
3843+
// Calls the stream.Writable() constructor.
3844+
super(options);
3845+
// ...
3846+
}
38463847
}
3847-
util.inherits(MyWritable, Writable);
38483848
```
38493849

38503850
Or, using the simplified constructor approach:
@@ -4194,20 +4194,6 @@ class MyReadable extends Readable {
41944194
}
41954195
```
41964196
4197-
Or, when using pre-ES6 style constructors:
4198-
4199-
```js
4200-
const { Readable } = require('node:stream');
4201-
const util = require('node:util');
4202-
4203-
function MyReadable(options) {
4204-
if (!(this instanceof MyReadable))
4205-
return new MyReadable(options);
4206-
Readable.call(this, options);
4207-
}
4208-
util.inherits(MyReadable, Readable);
4209-
```
4210-
42114197
Or, using the simplified constructor approach:
42124198
42134199
```js
@@ -4526,7 +4512,7 @@ changes:
45264512
45274513
<!-- eslint-disable no-useless-constructor -->
45284514
4529-
```js
4515+
```cjs
45304516
const { Duplex } = require('node:stream');
45314517

45324518
class MyDuplex extends Duplex {
@@ -4537,18 +4523,17 @@ class MyDuplex extends Duplex {
45374523
}
45384524
```
45394525
4540-
Or, when using pre-ES6 style constructors:
4526+
<!-- eslint-disable no-useless-constructor -->
45414527
4542-
```js
4543-
const { Duplex } = require('node:stream');
4544-
const util = require('node:util');
4528+
```mjs
4529+
import { Duplex } from 'node:stream';
45454530

4546-
function MyDuplex(options) {
4547-
if (!(this instanceof MyDuplex))
4548-
return new MyDuplex(options);
4549-
Duplex.call(this, options);
4531+
class MyDuplex extends Duplex {
4532+
constructor(options) {
4533+
super(options);
4534+
// ...
4535+
}
45504536
}
4551-
util.inherits(MyDuplex, Duplex);
45524537
```
45534538
45544539
Or, using the simplified constructor approach:
@@ -4723,7 +4708,7 @@ output on the `Readable` side is not consumed.
47234708
47244709
<!-- eslint-disable no-useless-constructor -->
47254710
4726-
```js
4711+
```cjs
47274712
const { Transform } = require('node:stream');
47284713

47294714
class MyTransform extends Transform {
@@ -4734,18 +4719,17 @@ class MyTransform extends Transform {
47344719
}
47354720
```
47364721
4737-
Or, when using pre-ES6 style constructors:
4722+
<!-- eslint-disable no-useless-constructor -->
47384723
4739-
```js
4740-
const { Transform } = require('node:stream');
4741-
const util = require('node:util');
4724+
```mjs
4725+
import { Transform } from 'node:stream';
47424726

4743-
function MyTransform(options) {
4744-
if (!(this instanceof MyTransform))
4745-
return new MyTransform(options);
4746-
Transform.call(this, options);
4727+
class MyTransform extends Transform {
4728+
constructor(options) {
4729+
super(options);
4730+
// ...
4731+
}
47474732
}
4748-
util.inherits(MyTransform, Transform);
47494733
```
47504734
47514735
Or, using the simplified constructor approach:

0 commit comments

Comments
 (0)