Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created August 21, 2008 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcoglan/6564 to your computer and use it in GitHub Desktop.
Save jcoglan/6564 to your computer and use it in GitHub Desktop.
var Globals = {
originals: [],
userDefined: [],
warned: [],
root: this,
initialize: function() {
if (this.originals.length > 0) return;
for (var key in this.root) this.originals.push(key);
},
register: function() {
for (var i = 0, n = arguments.length; i < n; i++)
this.userDefined.push(arguments[i]);
},
check: function() {
for (var key in this.root) {
if (this.originals.indexOf(key) == -1
&& this.userDefined.indexOf(key) == -1
&& this.warned.indexOf(key) == -1) {
console.warn('Global variable: ' + key);
this.warned.push(key);
}
}
},
run: function() {
var self = this;
setInterval(function() { self.check() }, 1000);
}
};
// Example -- variables from JS.Class
Globals.register('JS', 'it', 'its', 'require', 'undefined');
Globals.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment