Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active August 29, 2015 13:57
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 WebReflection/9626999 to your computer and use it in GitHub Desktop.
Save WebReflection/9626999 to your computer and use it in GitHub Desktop.
used to generate an overview of a generic JavaScript environment

Generates a Markdown friendly output similar to the one showed here.

(function show(object, name, all) {
  var f, k, later = [], list = ['### ' + name, '```javascript'];
  all.push(object);
  Object.getOwnPropertyNames(object).forEach(function(name) {
    list.push(name);
    if (/^[A-Z]/.test(name) && object[name] instanceof Object) {
      later.push([object, name]);
    }
  });
  list.push('```', '');
  while(later.length) {
    f = later.shift();
    k = f[1];
    f = f[0];
    if (all.indexOf(f[k]) < 0) {
      list.push(
        show(f[k], k, all)
      );
      if (typeof f[k] == 'function' && f[k].hasOwnProperty('prototype')) {
        list.push(
          show(f[k].prototype, k + '.prototype', all)
        );
      }
    }
  }
  return list.join('\n');
}(global, 'global', []));
@WebReflection
Copy link
Author

one line version:

(function show(d,f){var a,b,e=[],c=["### "+f,"```javascript"];Object.getOwnPropertyNames(d).forEach(function(a){c.push(a);/^[A-Z]/.test(a)&&d[a]instanceof Object&&e.push([d,a])});for(c.push("```","");e.length;)a=e.shift(),b=a[1],a=a[0],c.push(show(a[b],b)),"function"==typeof a[b]&&a[b].hasOwnProperty("prototype")&&c.push(show(a[b].prototype,b+".prototype"));return c.join("\n")})(this,"global");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment