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 Jan 31, 2017
1 parent 809ae9d commit c2156fc
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 c2156fc

Please sign in to comment.