简体   繁体   English

谷歌关闭编译器和jQuery

[英]google closure compiler and jquery

I copy-pasted my js code into the google compiler and when I copied it back into my application it didn't work. 我将js代码复制粘贴到google编译器中,当我将其复制回到应用程序中时不起作用。 I realized that my code needs jquery so I copied the jquery code and my code into the google compiler, hoping it would easily solve the problem, but it doesn't work either. 我意识到我的代码需要jquery,所以我将jquery代码和我的代码复制到google编译器中,希望它可以轻松解决问题,但是它也不起作用。

In chrome, the code bugs on the line $(document).K(function () { which is the document ready function. The error is Uncaught TypeError: Object [object Object] has no method 'K' 在chrome中,代码$(document).K(function () {是准备好文档的函数。错误是Uncaught TypeError: Object [object Object] has no method 'K'

What do I need to do to make it (tentatively) work? 我需要做些什么才能使其(暂时)起作用?

Thanks for your suggestions. 感谢您的建议。

Use @externs_url to "import" symbols in Google's Closure compiler: 使用@externs_url在Google的Closure编译器中“导入”符号:

// @externs_url https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/jquery-1.9.js

I recommend to use one of the externs as defined in contrib/externs , which only includes the names of all methods. 我建议使用contrib / externs中定义的extern之一 ,其中仅包括所有方法的名称。

Example

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @externs_url https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/jquery-1.9.js
// ==/ClosureCompiler==
$(document).ready(function(){alert(0);});  // Input

Output: 输出:

$(document).ready(function(){alert(0)});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM