Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save jonathansampson/b059b74fa006e072ec7d to your computer and use it in GitHub Desktop.

Select an option

Save jonathansampson/b059b74fa006e072ec7d to your computer and use it in GitHub Desktop.

Revisions

  1. jonathansampson revised this gist May 12, 2014. 1 changed file with 20 additions and 13 deletions.
    33 changes: 20 additions & 13 deletions Object-Crawler.js
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,46 @@
    (function ( global ) {
    /*global document, prompt */
    (function( global ) {

    "use strict";

    var response = {
    browser: {
    name: prompt( "Browser Name" ),
    version: prompt( "Browser Version" )
    browser: {
    name: prompt( "Browser Name? (Chrome, IExplorer, etc)" ),
    version: prompt( "Browser Version? (34, 11, etc)" )
    },
    root: "window",
    properties: Object.getOwnPropertyNames( global ).sort()
    };

    response.properties.forEach(function ( property, index, array ) {
    function addIfDistinct ( arr, key ) {
    if ( 0 > arr.indexOf( key ) ) {
    arr.push( key );
    }
    }

    response.properties.forEach(function ( prop, index, array ) {

    var obj = { "property": property },
    self = global[ property ],
    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();
    obj.own = Object.getOwnPropertyNames( self ).sort();
    while ( proto ) {
    Object.getOwnPropertyNames( proto ).forEach(function ( key ) {
    !~props.indexOf( key ) && props.push( key );
    });
    Object.getOwnPropertyNames( proto ).forEach(
    addIfDistinct.bind( null, props )
    );
    proto = Object.getPrototypeOf( proto );
    }

    obj["proto"] = props.sort();
    obj.proto = props.sort();

    if ( self.prototype ) {
    props = Object.getOwnPropertyNames( self.prototype );
    obj[".proto"] = props.sort();
    obj[ ".prototype" ] = props.sort();
    }
    }

  2. jonathansampson created this gist May 12, 2014.
    46 changes: 46 additions & 0 deletions Object-Crawler.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    (function ( global ) {

    "use strict";

    var response = {
    browser: {
    name: prompt( "Browser Name" ),
    version: prompt( "Browser Version" )
    },
    root: "window",
    properties: Object.getOwnPropertyNames( global ).sort()
    };

    response.properties.forEach(function ( property, index, array ) {

    var obj = { "property": property },
    self = global[ property ],
    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(function ( key ) {
    !~props.indexOf( key ) && props.push( key );
    });
    proto = Object.getPrototypeOf( proto );
    }

    obj["proto"] = props.sort();

    if ( self.prototype ) {
    props = Object.getOwnPropertyNames( self.prototype );
    obj[".proto"] = props.sort();
    }
    }

    array[ index ] = obj;

    });

    document.body.textContent = JSON.stringify( response, null, 4 );

    }( this ));