File tree Expand file tree Collapse file tree 2 files changed +15
-18
lines changed
Expand file tree Collapse file tree 2 files changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -700,6 +700,16 @@ Type: Runtime
700700
701701` REPLServer.turnOffEditorMode()` was removed from userland visibility.
702702
703+ < a id=" DEP0079" ></a>
704+ # ## DEP0079: Custom inspection function on Objects via .inspect()
705+
706+ Type: Documentation-only
707+
708+ Using a property named ` inspect` on an object to specify a custom inspection
709+ function for [` util.inspect()` ][] is deprecated. Use [` util.inspect.custom` ][]
710+ instead. For backwards compatibility with Node.js prior to version 6.4.0, both
711+ may be specified.
712+
703713[` Buffer.allocUnsafeSlow(size)` ]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
704714[` Buffer.from(array)` ]: buffer.html#buffer_class_method_buffer_from_array
705715[` Buffer.from(buffer)` ]: buffer.html#buffer_class_method_buffer_from_buffer
@@ -738,6 +748,8 @@ Type: Runtime
738748[` util._extend()` ]: util.html#util_util_extend_target_source
739749[` util.debug()` ]: util.html#util_util_debug_string
740750[` util.error()` ]: util.html#util_util_error_strings
751+ [` util.inspect()` ]: util.html#util_util_inspect_object_options
752+ [` util.inspect.custom` ]: util.html#util_util_inspect_custom
741753[` util.isArray()` ]: util.html#util_util_isarray_object
742754[` util.isBoolean()` ]: util.html#util_util_isboolean_object
743755[` util.isBuffer()` ]: util.html#util_util_isbuffer_object
Original file line number Diff line number Diff line change @@ -377,8 +377,8 @@ terminals.
377377<!-- type=misc -->
378378
379379Objects may also define their own ` [util.inspect.custom](depth, opts) `
380- (or, equivalently ` inspect(depth, opts) ` ) function that ` util.inspect() ` will
381- invoke and use the result of when inspecting the object:
380+ (or the equivalent but deprecated ` inspect(depth, opts) ` ) function that
381+ ` util.inspect() ` will invoke and use the result of when inspecting the object:
382382
383383``` js
384384const util = require (' util' );
@@ -388,7 +388,7 @@ class Box {
388388 this .value = value;
389389 }
390390
391- inspect (depth , options ) {
391+ [ util . inspect . custom ] (depth , options ) {
392392 if (depth < 0 ) {
393393 return options .stylize (' [Box]' , ' special' );
394394 }
@@ -427,21 +427,6 @@ util.inspect(obj);
427427// Returns: "{ bar: 'baz' }"
428428```
429429
430- A custom inspection method can alternatively be provided by exposing
431- an ` inspect(depth, opts) ` method on the object:
432-
433- ``` js
434- const util = require (' util' );
435-
436- const obj = { foo: ' this will not show up in the inspect() output' };
437- obj .inspect = function (depth ) {
438- return { bar: ' baz' };
439- };
440-
441- util .inspect (obj);
442- // Returns: "{ bar: 'baz' }"
443- ```
444-
445430### util.inspect.custom
446431<!-- YAML
447432added: v6.6.0
You can’t perform that action at this time.
0 commit comments