熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JavaScript:世界上誤解最深的語言[2]

2022-06-13   來源: JSP教程 

  The ECMA committee that has stewardship over the language is developing extensions which while well intentioned will aggravate one of the languages biggest problems: There are already too many versions This creates confusion

  ECMA委員會這門語言的管家正在對它進行擴展也在蓄意惡化它最大的問題有太多的版本這是混亂的根源

  Design Errors
  設計上的錯誤
 
  No programming language is perfect JavaScript has its share of design errors such as the overloading of + to mean both addition and concatenation with type coercion and the errorprone with statement should be avoided The reserved word policies are much too strict Semicolon insertion was a huge mistake as was the notation for literal regular expressions These mistakes have led to programming errors and called the design of the language as a whole into question Fortunately many of these problems can be mitigated with a good lint program

  沒有什麼編程語言是完美的JavaScript也有它設計上的錯誤比如重載的+號隨著類型的不同既表示相加又表示連接和本該避免的有錯誤傾向的 with 語句它的保留字策略過於嚴格分號的插入是一個巨大的錯誤比如作為字面正則表達式的符號時這些失誤已直接導致編程中的錯誤也使這門語言的整體設計遭人質疑還好這些問題中有許多都可以在良好的 lint 程序中得以緩解

  The design of the language on the whole is quite sound Surprisingly the ECMAScript committee does not appear to be interested in correcting these problems Perhaps they are more interested in making new ones

  這門語言的整體設計(上的問題)是相當明顯的奇怪的是ECMAScript委員會並沒有對修正其中存在的問題表現出太大的興趣也許他們更熱衷於制造新的問題

  Lousy Implementations
  糟糕的實現

  Some of the earlier implementations of JavaScript were quite buggy This reflected badly on the language Compounding that those implementations were embedded in horribly buggy web browsers

  JavaScript的一些早期實現有許多bug這反過來對語言本身產生了很壞的影響更糟糕的是這些滿是bug的實現是嵌入在滿是bug的web浏覽器中的

  Bad Books
  糟糕的書

  Nearly all of the books about JavaScript are quite awful They contain errors poor examples and promote bad practices Important features of the language are often explained poorly or left out entirely I have reviewed dozens of JavaScript books and I can only recommend one: JavaScript: The Definitive Guide (th Edition) by David Flanagan (Attention authors: If you have written a good one please send me a review copy)

  幾乎所有的JavaScript書都是相當可怕的它們包含錯誤包含不好的例子並鼓勵不好的做法JavaScript語言的一些重要特性它們要麼沒有解釋清楚要麼根本就沒有提及我看過很多JavaScript的書但我只能推薦一本David Flanagan著的 JavaScript: The Definitive Guide (th Edition) (《JavaScript權威指南 第四版》)(作者們請注意如果你們寫出了好書請發給我一份副本我給你們校對

  Substandard Standard
  准標准的標准

  The official specification for the language is published by ECMA The specification is of extremely poor quality It is difficult to read and very difficult to understand This has been a contributor to the Bad Book problem because authors have been unable to use the standard document to improve their own understanding of the language ECMA and the TC committee should be deeply embarrassed

  ECMA公布的官方語言規范的質量極其的差不僅難讀而且極其難懂它可為那些糟糕的書做出了不小的貢獻因為那些作者無法通過這個標准文檔來更深地理解這門語言ECMA和TC應該為此感到非常尴尬

  Amateurs業余者

  Most of the people writing in JavaScript are not programmers They lack the training and discipline to write good programs JavaScript has so much expressive power that they are able to do useful things in it anyway This has given JavaScript a reputation of being strictly for the amateurs that it is not suitable for professional programming This is simply not the case

  使用JavaScript的人大多不是程序員他們缺少寫良好程序的培訓和訓練JavaScript有非常強大的表現力不管怎樣他們也能使用它做有用的事情這給了JavaScript一個全然適合業余愛好者而不適合專業程序員的名聲這很明顯是一個錯誤

  ObjectOriented面向對象

  Is JavaScript objectoriented? It has objects which can contain data and methods that act upon that data Objects can contain other objects It does not have classes but it does have constructors which do what classes do including acting as containers for class variables and methods It does not have classoriented inheritance but it does have prototypeoriented inheritance

  JavaScript是面向對象的嗎?它有對象它的對象可以包含數據以及對數據進行操作的方法對象也可以包含其他的對象它沒有類但是它有構造函數來做類的事情包括聲明類的變量和方法它沒有面向類的繼承但是他有面向原型的繼承

  The two main ways of building up object systems are by inheritance (isa) and by aggregation (hasa) JavaScript does both but its dynamic nature allows it to excel at aggregation

  構建對象系統的兩大主要方法是繼承(isa)和聚合(hasa)這兩者JavaScript都有但是它的動態天性允許有比聚合更好的實現方式

  Some argue that JavaScript is not truly object oriented because it does not provide information hiding That is objects cannot have private variables and private methods: All members are public

  一些關於JavaScript不是真的面向對象的爭論其理由是它沒有提供信息隱藏也就是說JavaScript的對象沒有私有變量和私有方法它的所有成員都是公開的

  But it turns out that JavaScript objects canhave private variables and private methods (Click here now to find out how) Of course few understand this because JavaScript is the worlds most misunderstood programming language

  但是事實是JavaScript 的對象可以有私有變量和私有方法(點擊這裡來看如何實現)當然之所以很少有人知道這個是因為JavaScript是世界上誤解最深的語言嘛

  Some argue that JavaScript is not truly object oriented because it does not provide inheritance But it turns out that JavaScript supports not only classical inheritance but other code reuse patterns as well

  另一些關於JavaScript不是真的面向對象的爭論其理由是它沒有提供繼承但是事實是JavaScript不但支持經典的繼承而且支持其他一些代碼重用的模式

  Copyright Douglas Crockford All Rights Reserved Wrrrldwide

[]  []  


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20722.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.