Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Created August 24, 2017 14:12
Show Gist options
  • Select an option

  • Save codenamejason/543643f52cad963b958bae623f0b1d67 to your computer and use it in GitHub Desktop.

Select an option

Save codenamejason/543643f52cad963b958bae623f0b1d67 to your computer and use it in GitHub Desktop.
This can be useful to reveal "hidden" properties (properties in the prototype chain which are not accessible through the object, because another property has the same name earlier in the prototype chain). Listing accessible properties only can easily be done by removing duplicates in the array.
function listAllProperties(o) {
var objectToInspect;
var result = [];
for(objectToInspect = o; objectToInspect !== null; objectToInspect = Object.getPrototypeOf(objectToInspect)) {
result = result.concat(Object.getOwnPropertyNames(objectToInspect));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment