Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Last active August 29, 2015 13:57
Show Gist options
  • Save jonathansampson/9418482 to your computer and use it in GitHub Desktop.
Save jonathansampson/9418482 to your computer and use it in GitHub Desktop.
Enumerates all properties of an object, including those found along the prototype chain.
var output = (function ( object ) {
"use strict";
function getProperties ( object ) {
return object ? Object.getOwnPropertyNames( object )
.concat( getProperties( Object.getPrototypeOf( object ) ) ) : [] ;
}
function getUnique ( array ) {
return array.filter(function ( value, index ) {
return array.lastIndexOf( value ) === index;
});
}
return getUnique( getProperties( object ).sort() );
}( window ));
/* Choose how you'd like it output */
document.body.style.whiteSpace = "pre";
document.body.textContent = JSON.stringify( output, null, "\t" );
@jonathansampson
Copy link
Author

I reached out to @ifandelse regarding this approach and he had some really great insight. Greatly modified the approach based on his direction. Smart fellow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment