Last active
August 29, 2015 13:57
-
-
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.
This file contains hidden or 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
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" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.