0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

doc: note about custom inspect functions

See: https://github.com/nodejs/io.js/issues/1798

When an Object is printed in REPL, the actual representation can be
overriden by defining `inspect` method on the objects. This patch
includes a note about the same in the REPL documentation.

PR-URL: https://github.com/nodejs/io.js/pull/2142
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
This commit is contained in:
Sakthipriyan Vairamani 2015-07-09 18:54:21 +00:00
parent 0a7bf81d2f
commit d9f857df3b

View File

@ -237,3 +237,27 @@ The following key combinations in the REPL have these special effects:
- `<ctrl>D` - Similar to the `.exit` keyword.
- `<tab>` - Show both global and local(scope) variables
### Customizing Object displays in the REPL
The REPL module internally uses
[util.inspect()][], when printing values. However, `util.inspect` delegates the
call to the object's `inspect()` function, if it has one. You can read more
about this delegation [here][].
For example, if you have defined an `inspect()` function on an object, like this:
> var obj = { foo: 'this will not show up in the inspect() output' };
undefined
> obj.inspect = function() {
... return { bar: 'baz' };
... };
[Function]
and try to print `obj` in REPL, it will invoke the custom `inspect()` function:
> obj
{ bar: 'baz' }
[util.inspect()]: util.html#util_util_inspect_object_options
[here]: util.html#util_custom_inspect_function_on_objects