Skip to content

Commit

Permalink
console: improve code readability
Browse files Browse the repository at this point in the history
use object spread to make console code more readable

PR-URL: nodejs#24412
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
gengjiawen authored and refack committed Jan 10, 2019
1 parent f3cac61 commit a2340f4
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,26 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');
}

var prop = {
const prop = {
writable: true,
enumerable: false,
configurable: true
};
prop.value = stdout;
Object.defineProperty(this, '_stdout', prop);
prop.value = stderr;
Object.defineProperty(this, '_stderr', prop);
prop.value = Boolean(ignoreErrors);
Object.defineProperty(this, '_ignoreErrors', prop);
prop.value = new Map();
Object.defineProperty(this, '_times', prop);
prop.value = createWriteErrorHandler(stdout);
Object.defineProperty(this, '_stdoutErrorHandler', prop);
prop.value = createWriteErrorHandler(stderr);
Object.defineProperty(this, '_stderrErrorHandler', prop);
Object.defineProperty(this, '_stdout', { ...prop, value: stdout });
Object.defineProperty(this, '_stderr', { ...prop, value: stderr });
Object.defineProperty(this, '_ignoreErrors', {
...prop,
value: Boolean(ignoreErrors),
});
Object.defineProperty(this, '_times', { ...prop, value: new Map() });
Object.defineProperty(this, '_stdoutErrorHandler', {
...prop,
value: createWriteErrorHandler(stdout),
});
Object.defineProperty(this, '_stderrErrorHandler', {
...prop,
value: createWriteErrorHandler(stderr),
});

if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
Expand Down

0 comments on commit a2340f4

Please sign in to comment.