Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active December 18, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onionmk2/ab82c18e0d177c257990cbe593905ff8 to your computer and use it in GitHub Desktop.
Save onionmk2/ab82c18e0d177c257990cbe593905ff8 to your computer and use it in GitHub Desktop.
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