@@ -572,9 +572,10 @@ terminals.
572572
573573<!-- type=misc -->
574574
575- Objects may also define their own ` [util.inspect.custom](depth, opts) `
576- (or the equivalent but deprecated ` inspect(depth, opts) ` ) function that
577- ` util.inspect() ` will invoke and use the result of when inspecting the object:
575+ Objects may also define their own
576+ [ ` [util.inspect.custom](depth, opts) ` ] [ util.inspect.custom ] (or the equivalent
577+ but deprecated ` inspect(depth, opts) ` ) function, which ` util.inspect() ` will
578+ invoke and use the result of when inspecting the object:
578579
579580``` js
580581const util = require (' util' );
@@ -626,10 +627,41 @@ util.inspect(obj);
626627### util.inspect.custom
627628<!-- YAML
628629added: v6.6.0
630+ changes:
631+ - version: REPLACEME
632+ pr-url: https://github.com/nodejs/node/pull/20857
633+ description: This is now defined as a shared symbol.
629634-->
630635
631- A {symbol} that can be used to declare custom inspect functions, see
632- [ Custom inspection functions on Objects] [ ] .
636+ * {symbol} that can be used to declare custom inspect functions.
637+
638+ In addition to being accessible through ` util.inspect.custom ` , this
639+ symbol is [ registered globally] [ global symbol registry ] and can be
640+ accessed in any environment as ` Symbol.for('nodejs.util.inspect.custom') ` .
641+
642+ ``` js
643+ const inspect = Symbol .for (' nodejs.util.inspect.custom' );
644+
645+ class Password {
646+ constructor (value ) {
647+ this .value = value;
648+ }
649+
650+ toString () {
651+ return ' xxxxxxxx' ;
652+ }
653+
654+ [inspect ]() {
655+ return ` Password <${ this .toString ()} >` ;
656+ }
657+ }
658+
659+ const password = new Password (' r0sebud' );
660+ console .log (password);
661+ // Prints Password <xxxxxxxx>
662+ ```
663+
664+ See [ Custom inspection functions on Objects] [ ] for more details.
633665
634666### util.inspect.defaultOptions
635667<!-- YAML
@@ -2076,7 +2108,6 @@ Deprecated predecessor of `console.log`.
20762108[ `Array.isArray()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
20772109[ `ArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
20782110[ `ArrayBuffer.isView()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
2079- [ async function ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
20802111[ `assert.deepStrictEqual()` ] : assert.html#assert_assert_deepstrictequal_actual_expected_message
20812112[ `Buffer.isBuffer()` ] : buffer.html#buffer_class_method_buffer_isbuffer_obj
20822113[ `console.error()` ] : console.html#console_console_error_data_args
@@ -2118,6 +2149,9 @@ Deprecated predecessor of `console.log`.
21182149[ Module Namespace Object ] : https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects
21192150[ WHATWG Encoding Standard ] : https://encoding.spec.whatwg.org/
21202151[ Common System Errors ] : errors.html#errors_common_system_errors
2152+ [ async function ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
21212153[ constructor ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor
2154+ [ global symbol registry ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for
21222155[ list of deprecated APIS ] : deprecations.html#deprecations_list_of_deprecated_apis
21232156[ semantically incompatible ] : https://github.com/nodejs/node/issues/4179
2157+ [ util.inspect.custom ] : #util_util_inspect_custom
0 commit comments