Created
June 5, 2012 18:11
-
-
Save jwalsh/2876640 to your computer and use it in GitHub Desktop.
Show namespace pollution
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) { | |
// name, prefix, depth | |
var print = function(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 | |
for (var k in b) { | |
response += print(k, b, d + 1); | |
} | |
return response; | |
}; | |
var body = document.getElementsByTagName('body')[0]; | |
var frame = document.createElement('frame'); | |
frame.src = 'about:blank'; | |
body.appendChild(frame); | |
var clean = parent.frames[0]; | |
var status = document.getElementById('status'); | |
var output = ''; | |
for (var p in window) { | |
if (typeof clean.window[p] === 'undefined') { | |
if (typeof window[p] !== 'undefined') { | |
output += print(p, window, 2); | |
} | |
} | |
}; | |
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