Created
August 21, 2008 14:05
-
-
Save jcoglan/6564 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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