谷歌闭包编译器和jquery

谷歌闭包编译器和jquery

本文介绍了谷歌闭包编译器和jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的js代码复制粘贴到google编译器中,当我将其复制回我的应用程序时,它无法正常工作。我意识到我的代码需要jquery所以我将jquery代码和我的代码复制到谷歌编译器中,希望它能轻松解决问题,但它也不起作用。

I copy-pasted my js code into the google compiler and when I copied it back into my application it didn't work. 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.

在chrome中,代码错误行 $(document).K(function(){这是文档就绪函数。错误是未捕获TypeError:对象[object Object]没有方法'K'

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'

我需要做些什么才能使它(暂时)工作?

What do I need to do to make it (tentatively) work?

感谢您的建议。

推荐答案

使用 @externs_url 在Google的Closure编译器中导入符号:

Use@externs_url to "import" symbols in Google's Closure compiler:

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

我建议使用,其中包含y包括所有方法的名称。

I recommend to use one of the externs as defined in contrib/externs, which only includes the names of all methods.

// ==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

输出:

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

这篇关于谷歌闭包编译器和jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 11:16