-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: note about custom inspect functions #2142
Conversation
this delegation, | ||
[here](https://iojs.org/api/util.html#util_custom_inspect_function_on_objects). | ||
|
||
So, if you have defined `inspect` function on an object, like this |
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.
... defined an inspect
function ...
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.
Changed it now, thanks :-)
See: nodejs#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
eec353d
to
b08202a
Compare
bump |
|
||
> var obj = { foo: 'this will not show up in the inspect() output' }; | ||
undefined | ||
> obj.inspect = function(depth) { |
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.
Maybe remove depth
?
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.
Ah, copy/paste mistake. Thanks :-)
LGTM Otherwise. |
@Fishrock123 Addressed the comments. PTAL :-) |
Bump! |
@@ -237,3 +237,26 @@ 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 | |||
|
|||
|
|||
### Overriding representation of Objects in REPL |
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.
Maybe call this Customizing Object displays in the REPL
@cjihrig Thanks for the review. I changed the text now. PTAL. |
... }; | ||
[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 comment
The reason will be displayed to describe this comment to others. Learn more.
Period after function
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 just used :
. Should this be a .
?
LGTM minus a few comments. |
... }; | ||
[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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks :-)
@Fishrock123 Can you PTAL and give LGTM, so that I can land this? EDIT: CC @targos |
### Customizing Object displays in the REPL | ||
|
||
The REPL module internally uses | ||
[`util.inspect`](https://iojs.org/api/util.html#util_util_inspect_object_options), |
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.
The link should be relative. You can see how it's done in https://raw.githubusercontent.com/nodejs/io.js/master/doc/api/console.markdown
Thanks for pointing it out @targos :-) PTAL now. |
LGTM |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be referred to as inspect()
? I wish we had guidelines for that kind of thing... cc @nodejs/documentation
### Customizing Object displays in the REPL | ||
|
||
The REPL module internally uses | ||
[util.inspect()][], when printing values. But, `util.inspect` delegates the call |
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.
Nits but LGTM |
@Fishrock123 I incorporated the comments now. This already got 3 LGTMs. If no other suggestions, I ll merge this by 9:00 PM IST 24th Jul 2015 |
See: #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: #2142 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Thanks people, landed at d9f857d :-) |
See: #1798
When an Object is printed in REPL, the actual representation can be
overriden by defining
inspect
method on the objects. This patchincludes a note about the same in the REPL documentation