Google Closure Library 通过 jQuery 提供什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1690197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does Google Closure Library offer over jQuery?
提问by pestaa
Considering
考虑
- business background
- community support
- available extensions
- default set of features
- simplicity of use
- and reliability
- 商业背景
- 社区支持
- 可用的扩展
- 默认功能集
- 使用简单
- 和可靠性
why do you prefer one over the another?
为什么你更喜欢一个?
采纳答案by Wookai
I'll try to add my piece of information.
我会尝试添加我的信息。
More than another JS lib
不仅仅是另一个 JS 库
As I understand it, Google Closure is not only another JS library, but it is also a set of tools that will allow you to optimize your JS code. Working with jQuery gives you good tools and a lightweight library, but it does not minify your own code. The Closure compilerwill. The closure inspectormay also be useful, as sometimes minified code has a different behavior than the original one, and is a pain to debug. It integrates with Firebugand support unit tests, which are both developers' best friends nowadays.
据我了解,Google Closure 不仅是另一个 JS 库,而且还是一组可让您优化 JS 代码的工具。使用 jQuery 可为您提供良好的工具和轻量级库,但它不会缩小您自己的代码。该Closure编译器会。所述闭合检查员也可以是有用的,因为有时精缩码具有比原始一个不同的行为,并且是疼痛调试。它与Firebug集成并支持单元测试,这是当今开发人员最好的朋友。
Documentation
文档
I guess that as any new library VS a well established one, it will lack the availability of tons of extensions and tutorial that jQuery has. However, being pushed by Google should ensure that support and reliability will be both pretty good. The current documentationand tutorialboth seem really good, too.
我想,作为任何新库 VS 一个完善的库,它将缺乏 jQuery 拥有的大量扩展和教程的可用性。然而,被谷歌推动应该确保支持和可靠性都非常好。当前的文档和教程看起来也非常好。
Features
特征
The features of Closure look decent, though, and its modular architecture is promising, too. I guess Google has been using it internally for a long time, which means that you could expect all basic features (and more) to be implemented, and probably in a very optimized and scalable way. They are trying to present it as the STL of JavaScript, so they should have polished it.
不过,Closure 的功能看起来不错,而且其模块化架构也很有前途。我猜谷歌已经在内部使用它很长时间了,这意味着您可以期望所有基本功能(以及更多)都可以实现,并且可能以非常优化和可扩展的方式实现。他们试图将其呈现为 JavaScript 的 STL,因此他们应该对其进行润色。
After looking at the features more closely, it seems that this may be a step forward for web-applications development compared to existing libraries as jQuery. It guess it benefits internal developments at Google, but things like detecting the online state (see goog.events.OnlineHandler), easy integration of AJAX requests and JS actions in the browser history (see goog.History), or the legions of great widgets they provide (see goog.ui package) may help all of us building even more awesome webapps ;) !
在更仔细地查看功能之后,与现有的 jQuery 库相比,这似乎是 Web 应用程序开发的一个进步。它猜测它有利于 Google 的内部开发,但诸如检测在线状态(请参阅goog.events.OnlineHandler)、在浏览器历史记录中轻松集成 AJAX 请求和 JS 操作(请参阅goog.History)或大量出色的小部件之类的事情他们提供(参见goog.ui 包)可以帮助我们所有人构建更棒的 web 应用程序;)!
It comes with templates featuresthat integrates with Java (who said GWT?), so this may also be another plus for Closure.
它带有与Java 集成的模板功能(谁说GWT?),所以这也可能是 Closure 的另一个优点。
Ease of use
便于使用
Finally, it looks pretty simple to use. The syntax may be a bit more verbose than the short $ jQuery function, but with IDEs and auto-completion, it's not a real problem. Moreover, I'd say we can expect a good integration in IDEs like Eclipse, coming from Google.
最后,它看起来使用起来非常简单。语法可能比简短的 $ jQuery 函数稍微冗长一些,但是有了 IDE 和自动完成功能,这不是一个真正的问题。此外,我想说我们可以期待与来自 Google 的 Eclipse 等 IDE 的良好集成。
EDIT: as requested, let me say a few words about the GWT reference. Google Web Toolkit is a Java library that allows to create AJAX-enabled web interfaces and that generates (and optimizes) the required JavaScript code. As Google Closure allows to create Templates that can be used both client- and server-side (using JavaScript and Java), my guess is that it will soon be possible to use them jointly (if it's not already the case).
编辑:根据要求,让我就 GWT 参考说几句。Google Web Toolkit 是一个 Java 库,它允许创建支持 AJAX 的 Web 界面并生成(和优化)所需的 JavaScript 代码。由于 Google Closure 允许创建既可以在客户端也可以在服务器端使用的模板(使用 JavaScript 和 Java),我的猜测是很快就可以联合使用它们(如果还不是这样的话)。
回答by James Black
In my brief look at the API I find the differences between jQuery and Closure to be striking.
在我对 API 的简要介绍中,我发现 jQuery 和 Closure 之间的差异非常显着。
jQuery is basically just a simplified way to do many frequent operations in a cross-browser way.
jQuery 基本上只是一种以跨浏览器方式执行许多频繁操作的简化方式。
Closure is a framework that is very new, in that they provide a cross-browser way to use the <canvas>
tag, for example, and they have added new events.
Closure 是一个非常新的框架,例如,因为它们提供了一种跨浏览器的方式来使用<canvas>
标签,并且它们添加了新的事件。
So, this is adding onto what we typically do with javascript, they are taking many operations that people want to do and putting them into the API.
因此,这增加了我们通常使用 javascript 所做的事情,他们正在执行人们想做的许多操作并将它们放入 API。
For example, they have an event to tell if the online state has changed. So you can tell if the system is online.
例如,他们有一个事件来判断在线状态是否发生了变化。所以你可以判断系统是否在线。
They have javascript functions that use tools such as Google Gears, which continues with the fact that they have extended what can be done with Javascript.
他们有使用诸如 Google Gears 之类的工具的 javascript 函数,这延续了他们扩展了可以使用 Javascript 完成的功能的事实。
It will take me a couple of days to digest all the changes, but I can see that this could have a big impact on web applications that can be developed.
我需要几天时间来消化所有更改,但我可以看到这可能会对可以开发的 Web 应用程序产生重大影响。
回答by Petr Pridal
The biggest advantage of Closure Library is that is is designed for Closure Compiler. This opens completely new possibilities for JavaScript development...
Closure Library 最大的优势在于它是为 Closure Compiler 设计的。这为 JavaScript 开发开辟了全新的可能性......
The compiler has several cool features:
编译器有几个很酷的特性:
- It compiles readable JavaScript into compressed machine-readable JavaScript - it has the best compression ratioin "ADVANCED" mode.
- Documentation of the code with JSDoc Tags is important: the compiler reads it and you get warnings during compilation for typos in documentation, wrong use of a @constructor, wrong type of a variable, misuse of a field annotated with @private and @protected, etc.
- If you write a reusable JavaScript library, such as OpenLayers or Google Maps, you formally export your public API - and the compiler optimizes your internal code.
- The end applications can be compiled together with the library - and then the unused parts of the library are removed from the produced code. Dependencies are solved automatically by the compiler.
- Compiler accepts constants to remove unwanted functionality - this allows compilation only for particular browser such as Mobile WebKit, for only one of Quirks mode or Strict mode, compilation without support of IE6, etc.
- Debugging with FireBug is possible even for the compiled version of the source code.
- Compiler supports generation of dynamically loadable modules, which can significantly speed up loading of the end application, because the code for advanced functionality can be loaded only when it is required.
- 它将可读的 JavaScript 编译成压缩的机器可读的 JavaScript - 它在“高级”模式下具有最佳压缩率。
- 带有 JSDoc 标签的代码文档很重要:编译器会读取它,并且在编译过程中会收到警告,提示文档中的拼写错误、@constructor 的错误使用、变量的错误类型、使用 @private 和 @protected 注释的字段的误用,等等。
- 如果您编写了一个可重用的 JavaScript 库,例如 OpenLayers 或 Google Maps,您就正式导出了您的公共 API - 并且编译器会优化您的内部代码。
- 最终应用程序可以与库一起编译 - 然后从生成的代码中删除库中未使用的部分。依赖关系由编译器自动解决。
- 编译器接受常量以删除不需要的功能 - 这允许仅针对特定浏览器(例如 Mobile WebKit)进行编译、仅针对 Quirks 模式或 Strict 模式之一、不支持 IE6 的编译等。
- 即使对于源代码的编译版本,也可以使用 FireBug 进行调试。
- Compiler 支持动态加载模块的生成,这可以显着加快最终应用程序的加载速度,因为高级功能的代码只能在需要时加载。
For details have a look at: http://blog.klokantech.com/2010/12/closure-compiler-for-openlayers-3x.html
详情请看:http: //blog.klokantech.com/2010/12/closure-compiler-for-openlayers-3x.html
回答by Evgeny
Edit: take a look at this youtube videoit may answer some questions about Google Closure better.
编辑:看看这个 youtube 视频,它可能会更好地回答一些关于 Google Closure 的问题。
Probably the best sources of information on google closure are project discussion group, wiki, doc pages, demos and a yet unfinished book by Michael Bolinthat is now available from safari books site.
关于谷歌关闭的最佳信息来源可能是项目讨论组、维基、文档页面、演示和Michael Bolin尚未完成的书,现在可以从 safari 图书站点获得。
one thing I can tell right away - there is a steeper learning curve for closure
vs jQuery
but it may be well worth it due to the library's vastness, clear organization and the benefit of using it together with the compiler and the templating tool.
我可以马上告诉你的一件事 - closure
vs有一个更陡峭的学习曲线,jQuery
但由于库的庞大、清晰的组织以及将它与编译器和模板工具一起使用的好处,它可能非常值得。
closure
library in that respect is more like dojo
than jQuery
, and some concepts were borrowed from dojo
, according to Michael Bolin.
closure
库在这方面更像dojo
比jQuery
,和一些概念从借用dojo
,根据迈克尔波林。
google closure compiler uses JSDoc
documentation system which simultaneously (if created by the programmer correctly) provides documentation and enables catching many errors at compile time.
google 闭包编译器使用JSDoc
文档系统,该系统同时(如果由程序员正确创建)提供文档并在编译时捕获许多错误。
while function names are more verbose than jQuery
's, the compiler shrinks the code (using various optimization tactics) and the type checking will save a considerable time debugging the code, so time typing in the longer names is probably not an issue. At the same time longer names add readability.
虽然函数名比jQuery
's更冗长,但编译器会缩小代码(使用各种优化策略)并且类型检查将节省大量调试代码的时间,因此键入较长名称的时间可能不是问题。同时,更长的名称增加了可读性。
library supports browsers running in the quirks mode so that scripts could be embedded by other sites using "quirky" html
库支持以 quirks 模式运行的浏览器,以便其他站点可以使用“quirky” html 嵌入脚本
library works with (but does not depend upon) a javascript templating system called soy
that simplifies filling documents with content.
library 与(但不依赖于)一个称为 javascript 模板系统的系统一起工作soy
,该系统简化了用内容填充文档。
like jQuery
google closure
allows traversing dom structure with the string-based queries using a dedicated component of the library.
like jQuery
googleclosure
允许使用库的专用组件通过基于字符串的查询遍历 dom 结构。
closure
library relies on dot-delimited namespaces more like Java
- a very strong organizational feature.
closure
库更像是依赖点分隔的命名空间Java
- 一个非常强大的组织功能。
using such namespaces will incur overhead in uncompiled code, but in the compiled code those things are replace with short variable names.
使用这样的命名空间会在未编译的代码中产生开销,但在编译的代码中,这些东西被替换为短变量名。
回答by Davide Zanotti
回答by Nickolay
Maybe I'm not getting jQuery, but I haven't seen a real UI widgets collection there (there are plugins, yes, but you never know how well-tested they are and often there is no clear winner and/or the plugin lacks documentation).
也许我没有得到 jQuery,但我还没有在那里看到真正的 UI 小部件集合(有插件,是的,但你永远不知道它们经过了多么好的测试,而且通常没有明显的赢家和/或插件缺乏文档)。
Closure has, among other things, a widgets collection(see the demos tab), including, say, imageless buttonsused in gmail.
Closure 有一个小部件集合(参见演示选项卡),包括gmail 中使用的无图像按钮。
More generally, it has more functionality implemented as part of the release. It may not be a big thing, but I get annoyed with the sea of jQuery plugins when I'm looking for something as simple as a ajax history module or autocomplete.
更一般地说,它具有作为版本的一部分实现的更多功能。这可能不是什么大事,但是当我在寻找像 ajax 历史模块或自动完成这样简单的东西时,我对 jQuery 插件的海洋感到恼火。
Overall it's a huge library + set of tools and I'll be getting acquainted with it just to know what's available.
总的来说,它是一个巨大的库 + 一组工具,我将熟悉它只是为了知道有什么可用。
回答by Erik Reppen
I appreciate most of Google's contributions to the open source community and I'm sure it's got some cool stuff but overall I find Closure bulky, overwrought, and inelegant. If you must turn everything into Java I suppose it's downright spiffy.
我感谢 Google 对开源社区的大部分贡献,我相信它有一些很酷的东西,但总的来说,我发现 Closure 笨重、过度劳累且不优雅。如果你必须把所有东西都变成 Java,我想它是彻头彻尾的漂亮。
Edit:
编辑:
Fair enough. I didn't really compare. Closure is like a giant warehouse with every possible tool you could possibly want located... somewhere. Sort of like .NET or a massive Java library. Once you find what you need, you can find highly specific stuff that does highly specific jobs. And then for production you can remove all the cruft.
很公平。我真的没有比较。Closure 就像一个巨大的仓库,里面有你可能想要的所有可能的工具......某处。有点像 .NET 或一个庞大的 Java 库。一旦你找到了你需要的东西,你就可以找到非常具体的东西来完成非常具体的工作。然后对于生产,您可以删除所有的 cruft。
JQuery on the other hand, is more of an easily modified sonic screwdriver.
另一方面,JQuery 更像是一种易于修改的声波螺丝刀。
回答by Tereno
The Google Closure Library allows you to compile and optimize your JavaScript. It's not a library like jQuery is. jQuery is something that provides you with functions that allow you to write your own javascript faster.
Google Closure Library 允许您编译和优化您的 JavaScript。它不像 jQuery 那样是一个库。jQuery 为您提供了一些功能,让您可以更快地编写自己的 javascript。
Google Closure would help you make your own javascript code minimized to allow for a speedier delivery over the Internet.
Google Closure 将帮助您将自己的 javascript 代码最小化,以便更快地通过 Internet 交付。
Long story short, Google Closure is a tool while jQuery is a library similar to Prototype.
长话短说,Google Closure 是一个工具,而 jQuery 是一个类似于 Prototype 的库。