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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed Feb 1, 2017
1 parent 70ea38f commit 919e0cb
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 919e0cb

Please sign in to comment.