Best views on a polluted global javascript namespace

Is there an easy way to see which variables you (or other libraries) are polluted with the global namespace?

In the debug console (chrome), by typing this / this.window , you will see hundreds of objects, even without other libraries.

Is there a way to crop all standard browser space objects and return global variables (or better, classify by script file)?

+4
source share
3 answers

If you can run the script before loading any other scripts, you can save the list of properties of the embedded window:

 var builtInProps = [] for(key in window){ builtInProps.push(key); } 

Then after all your scripts load

 var pollution = []; for(key in window){ // check to make sure this key is in builtInProps, otherwise push it to "pollution" } 
+2
source

If you are using the Firebug plugin for FireFox ( http://getfirebug.com /), go to the DOM tab. Global objects are shown in bold:

http://screencast.com/t/9RHaIqoEV

(this is from my browser, where I am currently testing the backbone.js application)

+5
source

http://mir.aculo.us/dom-monster/ You can do the trick. Actually shows a lot of good.

0
source

All Articles