summaryrefslogtreecommitdiff
path: root/doc/api/util.md
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2017-11-11 10:35:01 -0600
committerAnna Henningsen <anna@addaleax.net>2017-12-01 21:00:33 +0100
commit31e0dbc0c700e7bb8fa453258ba0233975ece575 (patch)
tree8caaad41ef6275264c4d44722de64746be89c17a /doc/api/util.md
parentf6926d5d002273100a24a33a05ceb000eaae9fbe (diff)
downloadandroid-node-v8-31e0dbc0c700e7bb8fa453258ba0233975ece575.tar.gz
android-node-v8-31e0dbc0c700e7bb8fa453258ba0233975ece575.tar.bz2
android-node-v8-31e0dbc0c700e7bb8fa453258ba0233975ece575.zip
util: use @@toStringTag
uses @@toStringTag when creating the "tag" for an inspected value PR-URL: https://github.com/nodejs/node/pull/16956 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r--doc/api/util.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index 8c73242a5e..2d0f7fe365 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -350,6 +350,24 @@ changes:
The `util.inspect()` method returns a string representation of `object` that is
primarily useful for debugging. Additional `options` may be passed that alter
certain aspects of the formatted string.
+`util.inspect()` will use the constructor's name and/or `@@toStringTag` to make an
+identifiable tag for an inspected value.
+
+```js
+class Foo {
+ get [Symbol.toStringTag]() {
+ return 'bar';
+ }
+}
+
+class Bar {}
+
+const baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } });
+
+util.inspect(new Foo()); // 'Foo [bar] {}'
+util.inspect(new Bar()); // 'Bar {}'
+util.inspect(baz); // '[foo] {}'
+```
The following example inspects all properties of the `util` object: