Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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" );
@pseudosavant
Copy link

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.

@jonathansampson
Copy link
Author

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.

@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