翻譯 Secrets of the JavaScript Ninja 邊譯邊學(2)

Secrets of the JavaScript Ninja 邊譯邊學(2)

第一章 進入忍者的世界

原文
In this chapter:

  • A look at the purpose and structure of this book
  • Which libraries we will focus upon
  • What is advanced JavaScript programming?
  • Cross-browser authoring
  • Test suite examples

If you are reading this book, you know that there is nothing simple about creating effective
and cross-browser JavaScript code. In addition to the normal challenges of writing clean
code, we have the added complexity of dealing with obtuse browser differences and
complexities. To deal with these challenges, JavaScript developers frequently capture sets of
common and reusable functionality in the form of JavaScript libraries. These libraries vary
widely in approach, content and complexity, but one constant remains: they need to be easy
to use, incur the least amount of overhead, and be able to work across all browsers that we
wish to target.
It stands to reason then, that understanding how the very best JavaScript libraries are
constructed can provide us with great insight into how your own code can be constructed to
achieve these same goals. This book sets out to uncover the techniques and secrets used by
these world-class code bases, and to gather them into a single resource.
In this book we’ll be examining the techniques that are used to create two of the more
popular JavaScript libraries. Let’s meet them!

翻譯
在這一章節:

  • 快速瀏覽本書結構並介紹本書寫作目的
  • 介紹我們將着重講述的庫
  • 什麼是高級JavaScript編程?
  • 跨瀏覽器編程(寫作?)
  • 測試包示例

  如果您正在讀這本書,您一定知道創造高效運行的、跨瀏覽器的JavaScript代碼並不容易。除了面對編寫整潔代碼的常規挑戰,我們還要面對處理各種不同瀏覽器之差異造成的複雜性問題。爲了應對這些挑戰,JavaScript開發人員需要經常使用以JavaScript庫形式提供的通用和可重用功能。這些庫函數在方法、內容和複雜性各方面都有很大差異,但有一個不變的事實:它們是易用的,運行開銷小,並且能在我們需要使用的所有瀏覽器上正常工作。
  因此,理解那些最優秀的JavaScript庫如何構造可以讓我們深入瞭解如何構造您自己的代碼以實現上文提到的這些目標。這本書旨在揭示這些世界級的代碼庫的核心使用的技術和祕籍,並且把它們整合到一個源中。
  在這本書中,我們將研究創建兩個更加流行的JavaScript庫所使用的技術,讓我們見見它們!

原文
1.1 Our key JavaScript libraries
  The techniques and practices used to create two modern JavaScript libraries will be the focus
of our particular attention in this book. They are:

  • Prototype (http://prototypejs.org/), the godfather of the modern JavaScript libraries
    created by Sam Stephenson and released in 2005. This library embodies DOM, Ajax,
    and event functionality, in addition to object-oriented, aspect-oriented, and functional
    programming techniques.
  • jQuery (http://jquery.com) , created by John Resig and released in January of 2006.
    jQuery popularized the use of CSS selectors to match DOM content. Includes DOM,
    Ajax, event, and animation functionality.

  These two libraries currently dominate the JavaScript library market, being used on
hundreds of thousands of web sites, and interacted with by millions of users. Through
considerable use and feedback these libraries been refined over the years into the optimal
code bases that they are today. In addition to detailed examination of Prototype and jQuery,
we’ll also look at a few of the techniques utilized by the following libraries:

  • Yahoo! UI (http://developer.yahoo.com/yui), the result of internal JavaScript
    framework development at Yahoo! and released to the public in February of 2006.
    Yahoo! UI includes DOM, Ajax, event, and animation capabilities in addition to a
    number of pre-constructed widgets (calendar, grid, accordion, etc.).
  • base2 (http://code.google.com/p/base2), created by Dean Edwards and released
    March 2007. This library supports DOM and event functionality. Its claim-to-fame is
    that it attempts to implement the various W3C specifications in a universal, cross-
    browser manner.

  All of these libraries are well constructed and tackle their target problem areas
comprehensively. For these reasons they’ll serve as a good basis for further analysis, and
understanding the fundamental construction of these code bases gives us insight into the
process of world-class JavaScript library construction.
  But these techniques won’t only be useful for constructing large libraries, but can be
applied to all JavaScript coding, regardless of size.
  The make up of a JavaScript library can be broken down into three aspects: advanced use
of the JavaScript language, meticulous construction of cross-browser code, and a series of
best practices that tie everything together. We’ll be carefully analyzing these three aspects
to give us a complete knowledge base with which we can create our own effective JavaScript
code.

翻譯
1.1 我們最主要的JavaScript庫
  我們在本書中特別關注對象是用於創建兩個現代JavaScript庫的所使用的技術和實踐。它們是:

  • Prototype ,這是現代JavaScript庫的代表,由SamStephenson創造,於2005年發佈。該庫包含了DOM,Ajax和事件功能,還有面向對象,面向切面和基於方法的編程等技術。 (http://prototypejs.org/)
  • jQuery,由John Resig創建,2006年1月發佈。jquery推廣了使用css選擇器來匹配dom內容的技術。dom內容包括dom, Ajax、事件和動畫功能。(http://jquery.com)

  這兩個庫佔據了目前JavaScript庫主流市場,成千上萬的網站使用它們搭建並與數以百萬計的用戶進行交互。通過大量使用和反饋,這些庫改進成爲今天我們看到的這樣,擁有它們歷史上最優的核心代碼。除了對Prototype和JQuery進行詳細的研究以外,我們還將介紹以下庫使用的一些技術:

  • Yahoo!UI 雅虎JavaScript框架開發內部成果!2006年2月發佈。Yahoo!UI包含DOM,Ajax,event,動畫,還有一系列預先定義的組件(日曆,表格,摺疊菜單等) (http://developer.yahoo.com/yui)
  • base2 由Dean Edwards創建,2007年3月發佈。這一庫函數支持DOM和事件響應函數。它出名的地方在於它試圖用一種通用的、跨瀏覽器的方式實施W3C規範。

  所有這些庫都構建地很好,徹底解決了它們要解決的問題。基於這些原因,它們將作爲進一步分析的良好基礎,理解這些庫的核心基礎代碼的構建使我們能夠深入瞭解世界一流的JavaScript庫建設過程。
  但是這些技術不僅對構建大型庫有用,它們還可以應用於所有JavaScript編碼,無論其規模大小。
  一個JavaScript庫的構建可以分爲三個方面:javascript語言的高級應用、精心構建的跨瀏覽器代碼,以及一系列將一切聯繫在一起的最佳實踐。我們將仔細分析這三個方面,得到一個完整的知識基礎,用它我們可以創建我們自己的有效的JavaScript代碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章