Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathansampson/b059b74fa006e072ec7d to your computer and use it in GitHub Desktop.
Save jonathansampson/b059b74fa006e072ec7d to your computer and use it in GitHub Desktop.
Creates an object that reveals browser features and functionality
/*global document, prompt */
(function( global ) {
"use strict";
var response = {
browser: {
name: prompt( "Browser Name? (Chrome, IExplorer, etc)" ),
version: prompt( "Browser Version? (34, 11, etc)" )
},
root: "window",
properties: Object.getOwnPropertyNames( global ).sort()
};
function addIfDistinct ( arr, key ) {
if ( 0 > arr.indexOf( key ) ) {
arr.push( key );
}
}
response.properties.forEach(function ( prop, index, array ) {
var obj = { "property": prop },
self = global[ prop ],
regex = /[a-z]+\s[A-Z][a-z]+/,
props = [],
proto;
if ( self instanceof Object ) {
proto = Object.getPrototypeOf( self );
obj.own = Object.getOwnPropertyNames( self ).sort();
while ( proto ) {
Object.getOwnPropertyNames( proto ).forEach(
addIfDistinct.bind( null, props )
);
proto = Object.getPrototypeOf( proto );
}
obj.proto = props.sort();
if ( self.prototype ) {
props = Object.getOwnPropertyNames( self.prototype );
obj[ ".prototype" ] = props.sort();
}
}
array[ index ] = obj;
});
document.body.textContent = JSON.stringify( response, null, 4 );
}( this ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment