| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
not sure, but maybe "equivalent but deprecated"?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, you're correct. Even better might be or the equivalent but deprecated which is what I'll switch it to in a minute.
Sorry, something went wrong.
Just to give context, the alternative was only introduced a little more than a year ago in 6.4.0. I am perfectly fine with landing this in 8.x but I’d like to wait a little longer until we consider a runtime-deprecation. |
Sorry, something went wrong.
|
Labeling semver-minor as our docs indicate that is the minimum for a doc-only deprecation. |
Sorry, something went wrong.
|
can we check ecosystem usage of this before we land this? |
Sorry, something went wrong.
@evanlucas The same question was asked in #15549 and @refack answered (in #15549 (comment)) like this:
|
Sorry, something went wrong.
There was a problem hiding this comment.
+1 as a docs-only deprecation
Sorry, something went wrong.
querying for /\binspect\b/ results in more than 50KLOCs. In a partial manual review, I only picked up Q - #15549 (comment) |
Sorry, something went wrong.
|
Can someone confirm; will util.inspect fall back to the string "inspect" if util.inspect.custom is not available? Is there a plan in the future to change this behavior? |
Sorry, something went wrong.
|
Yes, the string inspect will still work. This is a docs only deprecation for now. Which means no runtime changes at all |
Sorry, something went wrong.
There was a problem hiding this comment.
It might be helpful to note that, if compatibility is desired, having the method present under both names is always going to work?
Sorry, something went wrong.
There was a problem hiding this comment.
I like the idea but I'm struggling with how to word it in a way that doesn't encourage people to use both if they're only using the Symbol. We don't want to create more messages if/when we move to a runtime deprecation. Suggestions welcome.
Sorry, something went wrong.
There was a problem hiding this comment.
@Trott The thing is, even if we move to a runtime deprecation, the symbol property will be the first one that’s detected, and the string property ignored – so if both are present, the runtime deprecation won’t be emitted… or am I misunderstanding what you’re saying?
Sorry, something went wrong.
There was a problem hiding this comment.
@addaleax Good point. I've added some text in a separate commit.
Sorry, something went wrong.
AFAICT the long term "plan" is to runtime deprecate then remove, but that cycle requires at least two major versions, and future consensus. |
Sorry, something went wrong.
The existence of `obj.inspect()` for custom inspection can cause people to unintentionally break `console.log()` and friends. This is a documentation-only deprecation that can hopefully land in 8.x. Refs: nodejs#15549
| function for [`util.inspect()`][] is deprecated. Use [`util.inspect.custom`][] | ||
| instead. | ||
| instead. (For backwards compatibility with Node.js prior to version 6.4.0, both | ||
| may be specified.) |
There was a problem hiding this comment.
instead (For backwards compatibility with Node.js prior to version 6.4.0, both may be specified). ?
Sorry, something went wrong.
There was a problem hiding this comment.
I think since it's a whole sentence (not just a clause) inside the parentheses the period should be inside.

http://www.thepunctuationguide.com/parentheses.html
Sorry, something went wrong.
There was a problem hiding this comment.
Perhaps the parentheses are unnecessary anyway?
Sorry, something went wrong.
|
Landed in c09c04f I removed the braces while landing. |
Sorry, something went wrong.
The existence of `obj.inspect()` for custom inspection can cause people to unintentionally break `console.log()` and friends. This is a documentation-only deprecation that can hopefully land in 8.x. PR-URL: #15631 Refs: #15549 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
This does not land cleanly on 8.x. Could you please manually backport. |
Sorry, something went wrong.
|
nvm I figured it out ☺️ |
Sorry, something went wrong.
The existence of `obj.inspect()` for custom inspection can cause people to unintentionally break `console.log()` and friends. This is a documentation-only deprecation that can hopefully land in 8.x. PR-URL: #15631 Refs: #15549 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
The existence of `obj.inspect()` for custom inspection can cause people to unintentionally break `console.log()` and friends. This is a documentation-only deprecation that can hopefully land in 8.x. PR-URL: #15631 Refs: #15549 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
The existence of `obj.inspect()` for custom inspection can cause people to unintentionally break `console.log()` and friends. This is a documentation-only deprecation that can hopefully land in 8.x. PR-URL: nodejs/node#15631 Refs: nodejs/node#15549 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
The existence of `obj.inspect()` for custom inspection can cause people to unintentionally break `console.log()` and friends. This is a documentation-only deprecation that can hopefully land in 8.x. PR-URL: #15631 Refs: #15549 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable Changes:
* deps:
* update npm to 5.4.2
#15600
* upgrade libuv to 1.15.0
#15745
* update V8 to 6.1.534.42
#15393
* dgram:
* support for setting dgram socket buffer size
#13623
* fs:
* add support O_DSYNC file open constant
#15451
* util:
* deprecate obj.inspect for custom inspection
#15631
* tools, build:
* there is a fancy new macOS installer
#15179
* Added new collaborator
* bmeurer - Benedikt Meurer - https://github.com/bmeurer
* kfarnung - Kyle Farnung - https://github.com/kfarnung
PR-URL: #15762
Notable Changes:
* deps:
* update npm to 5.4.2
#15600
* upgrade libuv to 1.15.0
#15745
* update V8 to 6.1.534.42
#15393
* dgram:
* support for setting dgram socket buffer size
#13623
* fs:
* add support O_DSYNC file open constant
#15451
* util:
* deprecate obj.inspect for custom inspection
#15631
* tools, build:
* there is a fancy new macOS installer
#15179
* Added new collaborator
* bmeurer - Benedikt Meurer - https://github.com/bmeurer
* kfarnung - Kyle Farnung - https://github.com/kfarnung
PR-URL: #15762
Notable Changes:
* deps:
* update npm to 5.4.2
nodejs/node#15600
* upgrade libuv to 1.15.0
nodejs/node#15745
* update V8 to 6.1.534.42
nodejs/node#15393
* dgram:
* support for setting dgram socket buffer size
nodejs/node#13623
* fs:
* add support O_DSYNC file open constant
nodejs/node#15451
* util:
* deprecate obj.inspect for custom inspection
nodejs/node#15631
* tools, build:
* there is a fancy new macOS installer
nodejs/node#15179
* Added new collaborator
* bmeurer - Benedikt Meurer - https://github.com/bmeurer
* kfarnung - Kyle Farnung - https://github.com/kfarnung
PR-URL: nodejs/node#15762
|
I saw the change, read documentation and played with the Node and the code, and still cannot quite get it... In order to provide custom console output for each of my custom types I used to do this: MyType.prototype.inspect = function(){
return 'CUSTOM VALUE';
}How am I to change this code for the latest Node.js? |
Sorry, something went wrong.
|
@vitaly-t basically, whenever you want your custom inspect function and care about older Node versions, also do: MyType.prototype.inspect = function(){
return 'CUSTOM VALUE';
};
if (util.inspect.custom) {
MyType.prototype[util.inspect.custom] = MyType.prototype.inspect;
}If you do not care about Node < 6.4.0, you can (and probably should) just use MyType.prototype[util.inspect.custom] = function(){
return 'CUSTOM VALUE';
};The reason for this is that it’s hard to tell for Node whether inspect was meant to be a custom inspection function for util.inspect, or somebody accidentally called it that way. With a symbol, that problem goes away. |
Sorry, something went wrong.
|
@addaleax Thank you! But if this is the case, then why the first code below works fine, while the one after doesn't? Works: const obj = {
inspect: () => {
return 'INSPECT';
}
};
console.log(obj);
//=> INSPECTDoesn't work: const obj = {
util: {
inspect: {
custom: () => {
return 'INSPECT';
}
}
}
};
console.log(obj);
//=> { util: { inspect: { custom: [Function: custom] } } }Node.js v8.7.0 |
Sorry, something went wrong.
|
@vitaly-t it's require('util').inspect.custom, eg: const obj = {
[require('util').inspect.custom]() {
return 'INSPECT';
}
};
console.log(obj); |
Sorry, something went wrong.
|
@ljharb Ouch,... tricky! I think documentation needs to get better on this one 😄 Thank you! Also, I'd like to figure out what that require('util').inspect.custom really returns. I can only see in the console for it saying Symbol(util.inspect.custom). Inspecting the inspection 😄 |
Sorry, something went wrong.
PRs are definitely very welcome!
I am not sure if this is helpful or not, but: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol (i.e. there isn’t really much more information contained in the value of util.inspect.custom than what Symbol(util.inspect.custom) says) |
Sorry, something went wrong.
|
Release team were -1 on landing on v6.x, if you disagree let us know. |
Sorry, something went wrong.
|
@gibfahn on landing the deprecation, the new symbol, or either? |
Sorry, something went wrong.
On landing the deprecation, though it wasn't a heavy -1, as with all backports we'd like to hear others' thoughts (we have a week to decide). Which is the new symbol? I don't see it in this PR. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The existence of obj.inspect() for custom inspection can cause people
to unintentionally break console.log() and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.
Refs: #15549
Checklist
Affected core subsystem(s)
util