Last active
December 18, 2016 14:26
-
-
Save onionmk2/ab82c18e0d177c257990cbe593905ff8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ObjectInspector { | |
constructor(target) { | |
this.target = target; | |
this["[[Class]]"] = Object.prototype.toString.call(this.target), | |
this.constructorName = this.target.constructor ? this.target.constructor.name : undefined, | |
this.props = Object.getOwnPropertyNames(this.target) | |
} | |
} | |
class ObjectChainInspector { | |
constructor(obj) { | |
this.obj = obj; | |
} | |
*[Symbol.iterator]() { | |
const inspector = new ObjectInspector(this.obj); | |
yield inspector; | |
let currentObj = this.obj; | |
while (currentObj.__proto__ !== null) { | |
currentObj = currentObj.__proto__; | |
yield new ObjectInspector(currentObj); | |
} | |
} | |
} | |
// how to use | |
const inspectors = new ObjectChainInspector({something: 'I want to inspect this'}); | |
for (const inspector of inspectors) { | |
console.dir(inspector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment