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" ); |
Good idea. Vendors explicitly state that prefixed code is experimental and not intended for production. Yet developers equal anything with a prefix as "shipped," and ready for broad consumption. This is reflected in tests, giving skewed impressions of where a browser truly is in supporting any given technology. Would love to know if/when you approach that effort.
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
Pretty cool code. I was thinking of writing something just like to estimate how much of a browser's 'HTML5' support is proprietary/prefixed. Kind of like an html5test.com where your score goes down for every -ms/-webkit/-moz it finds.