-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: note about custom inspect functions #2142
Changes from 5 commits
b08202a
95e47e8
a631a66
19a80c2
b2e6394
6839e19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. But, `util.inspect` delegates the call | ||
to the object's `inspect` function, if it has one. You can read more about | ||
this delegation [here][]. | ||
|
||
If you have defined an `inspect` function on an object, like this: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be referred to as |
||
|
||
> 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think either a period or colon should be fine here. I originally said period because your sentence was coming to a finish, but you also have a following code block, so either should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, thanks :-) |
||
|
||
> obj | ||
{ bar: 'baz' } | ||
|
||
[util.inspect()]: util.html#util_util_inspect_object_options | ||
[here]: util.html#util_custom_inspect_function_on_objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using However instead of But here. It's slightly more formal english.