是否可以将 Closure Compiler ADVANCED_OPTIMIZATIONS 与 jQuery 一起使用?
我不断收到错误消息,指出给定对象不存在该函数(重命名)。是否有发布或设置或其他东西可以使其发挥作用?
I keep getting errors that the function (renamed) does not exist for the given object. Is there a release or setting or something to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 Closure Compiler 高级模式与 jQuery 结合使用时,必须使用 jQuery 的 externs 文件。 Extern 文件将告诉编译器这些是保留方法并接受这些参数,并且参数数据类型应该是这样的,因此不要以这种方式缩小方法名称并检查参数数据类型。
您可以获取由 Google Developers 此处。此文件是为 jQuery-1.4.3 生成的。但目前可能适用于任何版本的 jQuery。新添加的方法可能不包含在该文件中,因此您应该将其添加到 externs 文件中,语法和同义词非常简单。
您还可以使用额外的编译器标志向编译器说明 externs 文件的位置。语法应该像这样
你也可以使用这个工具,它是闭包库的在线外部提取器。
You must use an externs file for jQuery when using Closure Compiler Advanced Mode with jQuery. Extern file will tell compiler these are reserved methods and accept these argument and argument data types should be like that, so do not minify method names and check argument data types in that way.
You can get externs file which is created by Google Developers here. This file generated for jQuery-1.4.3. But currently probably will work any version of jQuery. Newly added methods may not include in that file, so you should add it to externs file, syntax and synonyms are so simple.
Also you can say location of externs file to compiler by using an extra compier flag. Syntax should be like this
Also you can use this tool which is an online externs extractor for Closure Library.
您必须将 jQuery 声明为编译器的外部 ...但是我不确定是否有人制作了一个,有一个 1.3.2 的 extern 文件,但我还没有看到任何 1.4+ 版本。
编辑:此问题线程此处有社区构建了1.4版本。
You have to declare jQuery as an extern to the compiler...however I'm not sure if anyone's made one, there was an extern file for 1.3.2, but I haven't seen any 1.4+ versions.
Edit: this issue thread here has the community building a 1.4 version.
jQuery 与高级模式下的 Closure Compiler 不兼容。我同意使其兼容是一件非常好的事情,因为它的方法链接语法很容易实现原型虚拟化,从而大大提高执行速度。
事实上,在流行的 JavaScript 库中(除了 Closure Library 之外),只有 Dojo Toolkit 与 Closure Advanced 模式兼容。
http://dojo-toolkit.33424 .n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t
jQuery is not compatible (yet) with the Closure Compiler in advanced mode. I agree it would be a very good thing to make it compatible, because its method-chaining syntax lends very readily to prototype virtualization for much improved execution speed.
In fact, among the popular JavaScript libraries (other than Closure Library, that is), only the Dojo Toolkit is compatible with Closure Advanced mode.
http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t