Skip to content

Instantly share code, notes, and snippets.

@moudy
Created April 1, 2011 19:31
Show Gist options
  • Save moudy/898712 to your computer and use it in GitHub Desktop.
Save moudy/898712 to your computer and use it in GitHub Desktop.
handy code for monitoring global vars, should go at the end
if (true /* MONITOR_GLOBALS */) {
(function(){
var globals = {};
var startGlobals = [];
for (var j in window) {
globals[j] = true;
startGlobals.push(j);
}
if (true /* PRINT_INITIAL_GLOBALS */)
console.log("Initial globals: "+startGlobals.sort().join(', '));
setInterval(function() {
var newGlobals = [];
for (var j in window) {
if (!globals[j]) {
globals[j] = true;
newGlobals.push(j);
}
}
if (newGlobals.length > 0)
console.log("NEW GLOBALS: "+newGlobals.sort().join(', '));
}, 1000);
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment