防止闭包编译器重命名某些变量
我有一个带有全局对象的 javascript 文件,该对象不得重命名(来自 Google Analytics 异步跟踪器的 _gat
)。
该对象不得由 Google Closure 编译器重命名,因为 Google Analytics 会查找具有该特定名称的变量。
我研究了提到的 Javascript 文档符号: http: //code.google.com/closure/compiler/docs/js-for-compiler.html - 但是,我找不到有关变量“保护”的任何内容。
无论我使用简单编译还是高级编译,问题都存在。
如何确保 _gat
变量不被重命名?
I have a javascript file with a global object that must not be renamed (_gat
from the Google Analytics async tracker).
This object must not be renamed by the Google Closure Compiler as Google Analytics looks for a variable with this specific name.
I've looked into the Javascript Doc notations that are mentioned: http://code.google.com/closure/compiler/docs/js-for-compiler.html - However, I cannot find anything regarding the "protection" of a variable.
The problem exists no matter if I use simple or advanced compilation.
How can I ensure that the _gat
variable is not renamed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 Closure Compiler Web 应用程序,您可以设置
js_externs
。有关更多示例,请参阅高级编译和外部。Using Closure Compiler web app, you can set
js_externs
. Refer to Advanced Compilation and Externs for more examples.使用 base.js 中的 goog.exportSymbol 函数。文档位于:http://closure-library.googlecode.com/svn /docs/closure_goog_base.js.html
用法就像
Use the goog.exportSymbol function from base.js. Documentation is here: http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.html
Usage is like
请参阅http://closuretools.blogspot。 部分>>>
com/2011/01/property-by-any-other-name-part-1.html 关于“All Unquoted”将某些变量放入 ' ' 的 'bob' 阻止编译器重命名它们
See http://closuretools.blogspot.com/2011/01/property-by-any-other-name-part-1.html the part about "All Unquoted"
putting certain vars inside ' ' >>> 'bob' prevents them from being renamed by the compiler
如果它没有声明为您正在编译的代码的一部分,则外部声明是合适的:
http://code.google.com/closure/compiler/文档/api-tutorial3.html#externs
If it isn't declared as part of the code you are compiling than an extern declaration is appropriate:
http://code.google.com/closure/compiler/docs/api-tutorial3.html#externs