Skip to content
Browse files

platform: Avoid Closure Compiler munging the global platform object n…

…ame. [ded, jddalton]
  • Loading branch information...
1 parent 599ad05 commit dbf74f8b93f312c91e8675efb5027065a6c7a859 @jdalton jdalton committed Jun 2, 2011
Showing with 5 additions and 3 deletions.
  1. +4 −2 platform.js
  2. +1 −1 tests/tests.js
View
6 platform.js
@@ -147,7 +147,7 @@
* @returns {Object} The current platform object.
*/
function noConflict() {
- window.platform = old;
+ window['platform'] = old;
@mathiasbynens
BestieJS Modules member
mathiasbynens added a note Jun 3, 2011

Eww.

@jdalton
BestieJS Modules member
jdalton added a note Jun 3, 2011

Ya the window.platform inside noConflict() didn't actually mung, but other similar ones in benchmark.js did so I added it just to be safe.

@mathiasbynens
BestieJS Modules member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
return this;
}
@@ -392,6 +392,8 @@
} else if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
define(function() { return platform; });
} else {
- window.platform = platform;
+ // use square bracket notation so Closure Compiler won't mung `platform`
+ // http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
+ window['platform'] = platform;
}
}(this));
View
2 tests/tests.js
@@ -1343,7 +1343,7 @@
});
test('require("platform")', function() {
- equals(platform2 && platform2.description, platform.description, 'require("platform")');
+ equals((platform2 || { }).description, platform.description, 'require("platform")');
});
}());

0 comments on commit dbf74f8

Please sign in to comment.
Something went wrong with that request. Please try again.