Skip to content

Commit

Permalink
doc: more efficient example in the console.md
Browse files Browse the repository at this point in the history
Object.setPrototypeOf() -> Object.create()

PR-URL: #10451
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
vsemozhetbyt authored and jasnell committed Dec 27, 2016
1 parent 2b4dfeb commit 3e4dc60
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,20 @@ the default behavior of `console` in Node.js.

// Creates a simple extension of console with a
// new impl for assert without monkey-patching.
const myConsole = Object.setPrototypeOf({
assert(assertion, message, ...args) {
try {
console.assert(assertion, message, ...args);
} catch (err) {
console.error(err.stack);
}
}
}, console);
const myConsole = Object.create(console, {
assert: {
value: function assert(assertion, message, ...args) {
try {
console.assert(assertion, message, ...args);
} catch (err) {
console.error(err.stack);
}
},
configurable: true,
enumerable: true,
writable: true,
},
});

module.exports = myConsole;
```
Expand Down

0 comments on commit 3e4dc60

Please sign in to comment.