Browse Source

doc: more efficient example in the console.md

Object.setPrototypeOf() -> Object.create()

PR-URL: https://github.com/nodejs/node/pull/10451
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Vse Mozhet Byt 8 years ago
committed by James M Snell
parent
commit
3e4dc60fae
  1. 13
      doc/api/console.md

13
doc/api/console.md

@ -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) {
const myConsole = Object.create(console, {
assert: {
value: function assert(assertion, message, ...args) {
try {
console.assert(assertion, message, ...args);
} catch (err) {
console.error(err.stack);
}
}
}, console);
},
configurable: true,
enumerable: true,
writable: true,
},
});
module.exports = myConsole;
```

Loading…
Cancel
Save