deep-inspect
A function to inspect inherited properties as well
Installation
npm install deep-inspect
Options
The second argument to this function will be an options
object. It
accepts the following values. Please note that all are optional fields.
showHidden
depth
parentChainLevel
See below for explanations of the options.
showHidden
Setting this option to true
will show all the enumerable properties of the
object. Normally, when you iterate an object with a for..in
loop or with
Object.keys
, the non-enumerable properties will not be shown.
This must be a boolean value and the default value is false
.
depth
If the object is nested structure or the object has many child properties then
setting this option to a valid positive 32 bit integer value, will list all the
properties of the nested structure as well, till the level specified by depth
is reached.
This must be a valid 32 bit integer value and the default value is 1
.
parentChainLevel
This option allows to explore the inheritance chain as well. It will go to the
depth mentioned in parentChainLevel
and list down all the properties of all
the objects on the way.
There is no default value, but if not provided this will be ignored and none of the parent objects in the prototype chain will be inspected.
Usage
Inspecting primitives
var inspect = ;;// 1;// "thefourtheye";// undefined
Inspecting simple objects
var inspect = ;;// [];// {};// Object// └─┬ Key: "1"',// └── "2"'
Inspecting hidden (non-enumerable) properties
var inspect = ;var a = {};Object;;// Object// ├─┬ Key: "one"// │ └── "one"// └─┬ Key: "two"// └── "two";// Object// └─┬ Key: "one"// └── "one"
Inspecting inheritance chain (inherited properties)
var inspect = ; {}Parentprototypename = 'Parent'; {}Childprototype = Object;Childprototypeconstructor = Child; ;// Object// └─┬ [[Parent]] : Object// ├─┬ [[Parent]] : Object// │ ├─┬ [[Parent]] : Object// │ │ └── [[Parent]] : null// │ └─┬ Key: "name"// │ └── "Parent"// └─┬ Key: "constructor"// └── [Function Child]