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

Loading…
Cancel
Save