| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 16bdbb9 commit d2e1545
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -653,6 +653,16 @@ difference is that `querystring.parse()` does url decoding: | |||
| 653 | 653 | { '%E5%A5%BD': '1' } | |
| 654 | 654 | ``` | |
| 655 | 655 | ||
| 656 | + <a id="DEP0079"></a> | ||
| 657 | + ### DEP0079: Custom inspection function on Objects via .inspect() | ||
| 658 | + | ||
| 659 | + Type: Documentation-only | ||
| 660 | + | ||
| 661 | + Using a property named `inspect` on an object to specify a custom inspection | ||
| 662 | + function for [`util.inspect()`][] is deprecated. Use [`util.inspect.custom`][] | ||
| 663 | + instead. For backwards compatibility with Node.js prior to version 6.4.0, both | ||
| 664 | + may be specified. | ||
| 665 | + | ||
| 656 | 666 | [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size | |
| 657 | 667 | [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array | |
| 658 | 668 | [`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer | |
@@ -692,6 +702,8 @@ difference is that `querystring.parse()` does url decoding: | |||
| 692 | 702 | [`util._extend()`]: util.html#util_util_extend_target_source | |
| 693 | 703 | [`util.debug()`]: util.html#util_util_debug_string | |
| 694 | 704 | [`util.error()`]: util.html#util_util_error_strings | |
| 705 | + [`util.inspect()`]: util.html#util_util_inspect_object_options | ||
| 706 | + [`util.inspect.custom`]: util.html#util_util_inspect_custom | ||
| 695 | 707 | [`util.isArray()`]: util.html#util_util_isarray_object | |
| 696 | 708 | [`util.isBoolean()`]: util.html#util_util_isboolean_object | |
| 697 | 709 | [`util.isBuffer()`]: util.html#util_util_isbuffer_object | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -377,8 +377,8 @@ terminals. | |||
| 377 | 377 | <!-- type=misc --> | |
| 378 | 378 | ||
| 379 | 379 | Objects 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: | ||
| 382 | 382 | ||
| 383 | 383 | ```js | |
| 384 | 384 | const util = require('util'); | |
@@ -388,7 +388,7 @@ class Box { | |||
| 388 | 388 | this.value = value; | |
| 389 | 389 | } | |
| 390 | 390 | ||
| 391 | - inspect(depth, options) { | ||
| 391 | + [util.inspect.custom](depth, options) { | ||
| 392 | 392 | if (depth < 0) { | |
| 393 | 393 | return options.stylize('[Box]', 'special'); | |
| 394 | 394 | } | |
@@ -427,21 +427,6 @@ util.inspect(obj); | |||
| 427 | 427 | // Returns: "{ bar: 'baz' }" | |
| 428 | 428 | ``` | |
| 429 | 429 | ||
| 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 | - | ||
| 445 | 430 | ### util.inspect.custom | |
| 446 | 431 | <!-- YAML | |
| 447 | 432 | added: v6.6.0 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments