Skip to content

Commit 561c14b

Browse files
vsemozhetbytjasnell
authored andcommitted
doc: modernize and fix code examples in util.md
* Remove useless constructor. * Use template literals. * Update code example. Now all arrays with just holes are outputted the same way. In the fixed example, it was `[ <101 empty items> ]` twice. PR-URL: #13298 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 830049f commit 561c14b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

doc/api/util.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ ES6 example using `class` and `extends`
196196
const EventEmitter = require('events');
197197

198198
class MyStream extends EventEmitter {
199-
constructor() {
200-
super();
201-
}
202199
write(data) {
203200
this.emit('data', data);
204201
}
@@ -329,8 +326,8 @@ class Box {
329326
// Five space padding because that's the size of "Box< ".
330327
const padding = ' '.repeat(5);
331328
const inner = util.inspect(this.value, newOptions)
332-
.replace(/\n/g, '\n' + padding);
333-
return options.stylize('Box', 'special') + '< ' + inner + ' >';
329+
.replace(/\n/g, `\n${padding}`);
330+
return `${options.stylize('Box', 'special')}< ${inner} >`;
334331
}
335332
}
336333

@@ -392,7 +389,7 @@ option properties directly is also supported.
392389

393390
```js
394391
const util = require('util');
395-
const arr = Array(101);
392+
const arr = Array(101).fill(0);
396393

397394
console.log(arr); // logs the truncated array
398395
util.inspect.defaultOptions.maxArrayLength = null;

0 commit comments

Comments
 (0)