程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> JavaScript:世界上誤解最深的語言

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

編輯:關於JAVA

JavaScript, aka Mocha, aka LiveScript, aka JScript, aka ECMAScript, is one of the world's most popular programming languages. Virtually every personal computer in the world has at least one Javascript interpreter installed on it and in active use. JavaScript's popularity is due entirely to its role as the scripting language of the WWW. http://www.mscto.com

JavaScript,或者叫 Mocha,或者叫 LiveScript,或者叫 JScript,又或者叫 ECMAScript,是世界上最流行的編程語言之一。事實上世界上的每一台個人電腦都安裝並在頻繁使用至少一個JavaScript解釋器。JavaScript的流行完全是由於他在WWW腳本語言領域中的地位決定的。


http://www.mscto.com

Despite its popularity, few know that JavaScript is a very nice dynamic object-orIEnted general-purpose programming language. How can this be a secret? Why is this language so misunderstood?

盡管它很流行,但是很少有人知道JavaScript是一個非常棒的動態面向對象通用編程語言。這居然能成為一個秘密!這門語言為什麼被誤解如此之深?



軟件開發網

The Name

名字

The Java- prefix suggests that JavaScript is somehow related to Java, that it is a subset or less capable version of Java. It seems that the name was intentionally selected to create confusion, and from confusion comes misunderstanding. Javascript is not interpreted Java. Java is interpreted Java. JavaScript is a different language. 軟件開發網

Java- 前綴很容易使人聯想到Java,並認為它是Java的子集或簡化版的Java。看起來最初給它選這個名字是別有用心的,是故意混淆概念、故意制造"誤解"的。JavaScript不是解釋執行的Java。Java是解釋執行的Java。JavaScript是另外一種語言。


http://www.mscto.com

Javascript has a syntactic similarity to Java, much as Java has to C. But it is no more a subset of Java than Java is a subset of C. It is better than Java in the applications that Java (fka Oak) was originally intended for. 軟件開發網

Javascript的語法和Java有相似之處,這就像Java的語法和C很相像一樣。但是它不是Java的子集,就像Java不是C的子集一樣。它在Java(Oak)最初打算進軍的領域中比Java更好。 軟件開發網


http://www.mscto.com

Javascript was not developed at Sun Microsystems, the home of Java. JavaScript was developed at Netscape. It was originally called LiveScript, but that name wasn't confusing enough.

Javascript不是Sun Microsystems的產品,Sun是Java的家。JavaScript是在Netscape被開發出來的。它最初叫LiveScript,嗯……還是這個名字好。 http://www.mscto.com


The -Script suffix suggests that it is not a real programming language, that a scripting language is less than a programming language. But it is really a matter of specialization. Compared to C, JavaScript trades performance for expressive power and dynamism. http://www.mscto.com

-Script後綴讓人認為他不是一門真正的編程語言,和一門"編程語言"還有相當的差距。但是這只是應用領域的問題。和C相比,JavaScript是犧牲了性能但換來了豐富的表現力和靈活的形態。


 



Lisp in C's Clothing

披著C皮的Lisp

JavaScript's C-like syntax, including curly braces and the clunky for statement, makes it appear to be an ordinary procedural language. This is misleading because Javascript has more in common with functional languages like Lisp or Scheme than with C or Java. It has arrays instead of lists and objects instead of property lists. Functions are first class. It has closures. You get lambdas without having to balance all those parens.

JavaScript的類C語法,包括大括號和語句的形式,讓它看起來像普通的面向過程編程語言。這是一種誤解,因為Javascript和函數式語言,比如 Lisp 或 Scheme,有更多的相似之處,而不是和C或Java。它使用數組而不是列表,使用對象而不是屬性列表。函數是第一位的,它有閉包(closures 怎麼翻譯??),另外你還可以使用lambda表達式。




 

Typecasting

類型轉換

JavaScript was designed to run in Netscape Navigator. Its success there led to it becoming standard equipment in virtually all web browsers. This has resulted in typecasting. Javascript is the George Reeves of programming languages. JavaScript is well suited to a large class of non-Web-related applications

http://www.mscto.com

JavaScript最初被設計成在Netscape Navigator中運行,它在Navigator中的成功引領它成為事實上所有web浏覽器的標准裝備。這就造就了"類型轉換"。JavaScript是編程語言中的 George Reeves(超人),是大量非web程序的稱職之選。




 

Moving Target

移動靶

The first versions of JavaScript were quite weak. They lacked exception handling, inner functions, and inheritance. In its present form, it is now a complete object-orIEnted programming language. But many opinions of the language are based on its immature forms.

JavaScript的最初幾版非常弱,沒有異常處理,沒有內部函數和繼承。現如今,它已經成為完全面向對象的編程語言。但是這門語言的許多思想是基於它不成熟的形式的。 軟件開發網


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

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




 


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 error-prone 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 (4th 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 (4th 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 TC39 committee should be deeply embarrassed.

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




http://www.mscto.com

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一個”全然適合業余愛好者而不適合專業程序員“的名聲。這很明顯是一個錯誤。




http://www.mscto.com

Object-OrIEnted

面向對象

Is JavaScript object-oriented? 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 class-oriented inheritance, but it does have prototype-orIEnted inheritance.

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


The two main ways of building up object systems are by inheritance (is-a) and by aggregation (has-a). JavaScript does both, but its dynamic nature allows it to Excel at aggregation.

構建對象系統的兩大主要方法是繼承(is-a)和聚合(has-a)。這兩者JavaScript都有,但是它的動態天性允許有比聚合更好的實現方式。 http://www.mscto.com


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 can have private variables and private methods. (Click here now to find out how.) Of course, few understand this because JavaScript is the world's 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不但支持經典的繼承,而且支持其他一些代碼重用的模式。 軟件開發網

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved