Last active
August 29, 2015 14:01
-
-
Save jonathansampson/b059b74fa006e072ec7d to your computer and use it in GitHub Desktop.
Creates an object that reveals browser features and functionality
This file contains 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
/*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