teleball
teleball

Reputation: 4662

better views of javascript polluted global namespace

Is there an easy way to see what variables you (or other libraries) have polluted to the global namespace?

In the (chrome) debugger console, typing this/this.window reveals hundreds of objects, even without other libraries.

Is there a way to have it prune all of the standard browser space objects and return globals (or better, categorized by script file)?

Upvotes: 4

Views: 261

Answers (3)

morgancodes
morgancodes

Reputation: 25265

If you can run a script before any other scripts load, you can store a list of the built-int window properties:

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"
}

Upvotes: 2

Philip Schweiger
Philip Schweiger

Reputation: 2734

If you use the Firebug plugin for FireFox (http://getfirebug.com/), look at the DOM tab. The global objects are in bold:

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

(this is from my browser where I'm currently unit testing a backbone.js app)

Upvotes: 5

hookedonwinter
hookedonwinter

Reputation: 12666

http://mir.aculo.us/dom-monster/ Might do the trick. Shows a lot of good stuff, actually.

Upvotes: 0

Related Questions