Skip to content

Commit 919e0cb

Browse files
vsemozhetbytMylesBorins
authored andcommitted
doc: more efficient example in the console.md
Object.setPrototypeOf() -> Object.create() PR-URL: #10451 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 70ea38f commit 919e0cb

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

doc/api/console.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,20 @@ the default behavior of `console` in Node.js.
135135

136136
// Creates a simple extension of console with a
137137
// new impl for assert without monkey-patching.
138-
const myConsole = Object.setPrototypeOf({
139-
assert(assertion, message, ...args) {
140-
try {
141-
console.assert(assertion, message, ...args);
142-
} catch (err) {
143-
console.error(err.stack);
144-
}
145-
}
146-
}, console);
138+
const myConsole = Object.create(console, {
139+
assert: {
140+
value: function assert(assertion, message, ...args) {
141+
try {
142+
console.assert(assertion, message, ...args);
143+
} catch (err) {
144+
console.error(err.stack);
145+
}
146+
},
147+
configurable: true,
148+
enumerable: true,
149+
writable: true,
150+
},
151+
});
147152

148153
module.exports = myConsole;
149154
```

0 commit comments

Comments
 (0)