Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving global variable checker into its own file.

  • Loading branch information...
commit 05fc85dfb6d16e21fbaa04950d4b79d9521041d1 1 parent aa9494b
@jcoglan jcoglan authored
Showing with 36 additions and 35 deletions.
  1. +35 −0 test/globals.js
  2. +1 −35 test/test.html
View
35 test/globals.js
@@ -0,0 +1,35 @@
+var Globals = {
+ originals: [],
+ userDefined: [],
+ warned: [],
+
+ initialize: function() {
+ if (this.originals.length > 0) return;
+ for (var key in window) 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 window) {
+ 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);
+ }
+};
+
+Globals.register('JS', 'it', 'its', 'require', 'undefined');
+Globals.initialize();
+
View
36 test/test.html
@@ -7,41 +7,7 @@
<title>JS.Class tests</title>
<script src="prototype.js" type="text/javascript" charset="utf-8"></script>
<script src="unittest.js" type="text/javascript" charset="utf-8"></script>
- <script type="text/javascript">
- var Globals = {
- originals: [],
- userDefined: [],
- warned: [],
-
- initialize: function() {
- if (this.originals.length > 0) return;
- for (var key in window) 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 window) {
- 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);
- }
- };
-
- Globals.register('JS', 'it', 'its', 'require', 'undefined');
- Globals.initialize();
- </script>
+ <script src="globals.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
timeA = Number(new Date);
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.