Commit 7d14dd9b authored by Christopher Monsanto's avatar Christopher Monsanto
Browse files

util: display constructor when inspecting objects

This commit modifies util.inspect(obj) to additionally show the name of
the function that constructed the object. This often reveals useful
information about the object's prototype. In other words, instead of

> new Cls
{}

we have

> new Cls
Cls {}

This also works with exotic objects:

> class ArrayCls extends Array {}
> new ArrayCls(1, 2, 3)
ArrayCls [ 1, 2, 3 ]

The names of "trivial" constructors like Object and Array are not shown,
unless there is a mismatch between the object representation and the
prototype:

> Object.create([])
Array {}

This feature is inspired by browser devtools.

PR-URL: https://github.com/nodejs/io.js/pull/1935


Reviewed-By: default avatarRoman Reiss <me@silverwind.io>
Reviewed-By: default avatarJeremiah Senkpiel <fishrock123@rocketmail.com>
parent 6ad99ac1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment