Browse Source

console: console.dir() accepts options object

This features comes from the need of adding extra options when displaying
the object using console.dir().

console.dir() accepts now a second parameter that is passed to util.inspect()
in order to provide extra options to the output. These options are: depth, color
and showHidden. More information about these options in util.inspect() documentation.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
archived-io.js-v0.10
Xavi Magrinyà 11 years ago
committed by Fedor Indutny
parent
commit
1cd48c7ae5
  1. 4
      doc/api/console.markdown
  2. 9
      lib/console.js

4
doc/api/console.markdown

@ -47,10 +47,10 @@ Same as `console.error`.
## console.dir(obj, [options]) ## console.dir(obj, [options])
Uses `util.inspect` on `obj` and prints resulting string to stdout. This function Uses `util.inspect` on `obj` and prints resulting string to stdout. This function
bypasses any custom `inspect()` function on `obj`. An optional *options* object bypasses any custom `inspect()` function on `obj`. An optional *options* object
may be passed that alters certain aspects of the formatted string: may be passed that alters certain aspects of the formatted string:
- `showHidden` - if `true` then the object's non-enumerable properties will be - `showHidden` - if `true` then the object's non-enumerable properties will be
shown too. Defaults to `false`. shown too. Defaults to `false`.
- `depth` - tells `inspect` how many times to recurse while formatting the - `depth` - tells `inspect` how many times to recurse while formatting the

9
lib/console.js

@ -66,12 +66,9 @@ Console.prototype.error = Console.prototype.warn;
Console.prototype.dir = function(object, options) { Console.prototype.dir = function(object, options) {
if (typeof options === 'object' && options !== null) { this._stdout.write(util.inspect(object, util._extend({
options.customInspect = false; customInspect: false
} else { }, options)) + '\n');
options = { customInspect: false };
}
this._stdout.write(util.inspect(object, options) + '\n');
}; };

Loading…
Cancel
Save