(2)入门指南——(3)为什么jquery工作的很好(Why jQuery works well)
With the resurgence of interest in dynamic HTML comes a proliferation of JavaScript frameworks. Some are specialized, focusing on just one or two of the above tasks. Others attempt to catalog every possible behavior and animation, and serve these all up pre-packaged. To maintain the wide range of features outlined above while remaining relatively compact, jQuery employs several strategies:随着对动态html内容的兴趣的复苏,已经产生了很多js框架,一些专门化的关注于仅仅一两个的以上的任务。其他企图处理所有可能的行为和动画,服务所有的没有希望的简易包装。为了在相对简单的同时实现上面提到的很大范围的特点,jquery使用了以下几个策略:
Leverage knowledge of CSS: By basing the mechanism for locating page elements on CSS selectors, jQuery inherits a terse, yet legible, way of expressing a document's structure. The jQuery library becomes an entry point for designers who want to add behaviors to their pages because a prerequisite for doing professional web development is to have knowledge of CSS syntax.
使用css的知识:通过使用css选择器查找元素的机制,jquery继承了一个简洁的清晰的表达文件结构的方法。jquery成为了想为自己的网页添加行为的设计师开始的点,因为做专业的wen开发的先决条件就是有css语法知识。
Support extensions: In order to avoid feature creep, jQuery relegates specialcase uses to plugins. The method for creating new plugins is 易做图 and well-documented, which has spurred the development of a wide variety of inventive and useful modules. Most of the features in the basic jQuery download are internally realized through the plugin architecture, and can be removed if desired, yielding an even smaller library.
支持扩展:为了避免功能变更,jquery把特殊场景下使用的功能交由插件实现。创建新插件的功能很简单而且文档写的很好,这鼓舞了很多中的有用的模块的发展。大部分的下载下来的基础jquery中的大部分特点在内部通过插件机制实现,如果需要的话,可以被移除,生成一个甚至更小的js库。
Abstract away browser quirks: An unfortunate reality of web development is that each browser has its own set of deviations from published standards. A significant portion of any web application can be relegated to handle features differently on each platform. While the ever-evolving browser landscape makes a perfectly browser-neutral code base impossible for some advanced features, jQuery adds an abstraction layerthat normalizes the common tasks, reducing the size of code while tremendously simplifying it.
解决浏览器兼容性问题:对web开发来说,有一个不幸的事实——每一个浏览器都有自己一系列的与发布的标准的偏差,对任何一个web应用来说,一个重要的部分就是处理每一个平台的不同。然而多种浏览器平台胆汁创造完美的浏览器兼容的待吧对某些高级的功能来说使几乎不可能的。jquery添加了一个抽象层,使这些平常的任务变的正常,在简化的同时缩短了代码的大小。
Always work with sets: When we instruct jQuery, "Find all elements with the class collapsibleand hide them," there is no need to loop through each returned element. Instead, methods such as .hide()are designed to automatically work on sets of objects instead of individual ones. This technique, called implicit iteration, means that many looping constructs become unnecessary, shortening code considerably.
同时处理一系列元素:当我们命令jquery:"找到所有带有collapsible的类,并隐藏他们",我们不需要通过每一个返回的值循环操作。相反,.hide()这样的方法被设计的就是自动和一系列的对象一起工作。而不是和分离的。这种技术被称之为隐式迭代,意味着很多循环可以不是必须的,优雅的减少了代码。
Allow multiple actions in one line: To avoid overuse of temporary variables or wasteful repetition, jQuery employs a programming pattern called chainingfor the majority of its methods. This means that the result of most operations on an object is the object itself, ready for the next action to be applied to it.
允许在一行代码中操纵多个动作:为了避免滥用临时变量和浪费的重复,jquery使用了被称之为chaining的编程模式作为他的方法的主体。这意味着对一个对象的大部分操作的返回值是这个对象自己,准备好了让下一个操作去使用。
These strategies have kept the jQuery package slim—roughly 30 KB, compressed—while at the same time providing techniques to keep our custom code that uses the library compact.
这些策略让jquery变的很轻,压缩后大约只有30kb,同时提供技术让我们让使用了jquery的普通的代码变的简洁。
The elegance of the library comes about partly by design, and partly due to the evolutionary process spurred by the vibrant community that has sprung up around the project. Users of jQuery gather to discuss not only the development of plugins, but also enhancements to the core library. The users and developers also assist in continually improving the official project documentation,which can be found at http://api.jquery.com.
jquery代码的优雅部分源于设计,部分源于受围绕jquery如雨后春笋般建立的充满生机的社区的鼓舞而发生的进化。jquery的用户聚集在一起不仅仅讨论开发插件,同时讨论增强核心库的功能。用户和开发者也帮助持续提易做图方项目的文档,你可以在 http://api.jquery.com上找到这些文档。
Despite all of the efforts required to engineer such a flexible and robust system, the end product is free for all to use. This open source project is dually licensed under the MIT License(to permit free use of jQuery on any site and facilitate its use within proprietary software) and the GNU Public License(appropriate for inclusion in other GNU-licensed open-source projects).
尽管付出了很大的努力去开发这样灵活而且健壮的系统,最终的产品依然是对所有人免费的。这个开源项目在MIT许可(允许在任何站点上易做图jquery,同时在正确的软件上正确的促进他的使用)和GNU公共许可(包含其他GNU许可的开源项目是可以的)的双重许下。
补充:web前端 , JavaScript ,