From 561c14ba12a60469f1a19e8ea2328a3be247cbbe Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 30 May 2017 17:03:00 +0300 Subject: [PATCH] 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: /~https://github.com/nodejs/node/pull/13298 Reviewed-By: Michael Dawson Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- doc/api/util.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/api/util.md b/doc/api/util.md index 6e35185d024c33..ed0f2882e9f4f3 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -196,9 +196,6 @@ ES6 example using `class` and `extends` const EventEmitter = require('events'); class MyStream extends EventEmitter { - constructor() { - super(); - } write(data) { this.emit('data', data); } @@ -329,8 +326,8 @@ class Box { // Five space padding because that's the size of "Box< ". const padding = ' '.repeat(5); const inner = util.inspect(this.value, newOptions) - .replace(/\n/g, '\n' + padding); - return options.stylize('Box', 'special') + '< ' + inner + ' >'; + .replace(/\n/g, `\n${padding}`); + return `${options.stylize('Box', 'special')}< ${inner} >`; } } @@ -392,7 +389,7 @@ option properties directly is also supported. ```js const util = require('util'); -const arr = Array(101); +const arr = Array(101).fill(0); console.log(arr); // logs the truncated array util.inspect.defaultOptions.maxArrayLength = null;