[英]How to prevent Closure Compiler from creating a particular variable name in the global name space?
I'm familiar with the concept of using string literals and exporting to prevent Closure from renaming variables, but how do I prevent Closure from using a variable name that is used as a global variable by other code (which I did not write)? 我熟悉使用字符串文字和导出以防止Closure重命名变量的概念,但是如何防止Closure使用由其他代码(我没写过)用作全局变量的变量名?
Example, below was created for a member function of a closure: 下面的示例是为闭包的成员函数创建的:
function $() {
var a;
if(1 > N) {
return-1
}
a = Math.pow(1 + Q, F);
return .....
}
Above gets clobbered when jQuery is loaded. 当加载jQuery时,上面会被破坏。
I'm using the command line compiler and this is my command line: 我正在使用命令行编译器,这是我的命令行:
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --formatting=pretty_print --output_wrapper PGS --js common.v2.0.raw.js --module common_min:1 --js page_code.raw.js --module page_code_min:1:common_min
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --formatting = pretty_print --output_wrapper PGS --js common.v2.0.raw.js --module common_min:1 --js page_code.raw.js --module page_code_min: 1:common_min
I thought the output_wrapper
option is used to solve this problem, but either I'm misunderstanding its purpose or I'm misusing it. 我认为
output_wrapper
选项用于解决这个问题,但要么我误解了它的目的,要么我误用了它。
TIA. TIA。
The answer is externs . 答案是外部 。
Externs define symbols in external code. Externs在外部代码中定义符号。 They have two main purposes:
它们有两个主要目的:
In your case you can include an existing extern for jQuery. 在您的情况下,您可以包含jQuery的现有extern。 There is one for each major version in the project contrib folder .
项目contrib文件夹中的每个主要版本都有一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.