Created
June 5, 2012 20:07
-
-
Save jwalsh/2877485 to your computer and use it in GitHub Desktop.
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
(function(global, undefined) { | |
var MAXDEPTH = 10; | |
// name, prefix, depth | |
var print = function(n, p, d) { | |
if (d > MAXDEPTH) { | |
return new Error('MAXDEPTH exceeded'); | |
} | |
console.log(n, p, d); | |
var b = p[n]; | |
// Allow base indenting based on the depth | |
var response = '\n' + | |
(new Array(d).join(' ')) + | |
n + | |
' (' + (typeof b) + ')'; | |
// Could apply hasOwnProperty filter | |
// This doesn't account for functions with child properties | |
// Don't iterate through the lenght of the string | |
if (typeof b !== 'string') { | |
for (var k in b) { | |
if (b.hasOwnProperty(k)) { | |
response += print(k, b, d + 1); | |
} | |
} | |
} | |
return response; | |
}; | |
var body = document.getElementsByTagName('body')[0]; | |
// Establish a baseline of an unpolluted namespace in a new frame | |
var frame = document.createElement('frame'); | |
frame.src = 'about:blank'; | |
body.appendChild(frame); | |
var clean = parent.frames[0]; | |
var output = ''; | |
for (var p in window) { | |
if (typeof clean.window[p] === 'undefined') { | |
if (typeof window[p] !== 'undefined') { | |
output += print(p, window, 1); | |
} | |
} | |
}; | |
var report = document.createElement('pre'); | |
report.innerHTML = output; | |
body.appendChild(report); | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment