JavaScript-世界上誤解最深的語言分析
JavaScript,是世界上最流行的編程語言之一
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是一個(gè)非常棒
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- 前綴很容易使人聯(lián)想到Java,并認(rèn)為它是Java的子集或簡(jiǎn)化版
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有相似之處
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的產(chǎn)品,Sun是Java的家
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.
-Script后綴讓人認(rèn)為他不是一門真正的編程語言,和一門"編程語言
Lisp in C's Clothing
披著C皮的LispJavaScript'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語法,包括大括號(hào)和語句的形式
Typecasting
類型轉(zhuǎn)換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
JavaScript最初被設(shè)計(jì)成在Netscape Navigator中運(yùn)行,它在Navigator中的成功引領(lǐng)它
Moving Target
移動(dòng)靶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委員會(huì),這門語言的管家,正在對(duì)它進(jìn)行擴(kuò)展,也在蓄意惡化它最大的問題
Design Errors
設(shè)計(jì)上的錯(cuò)誤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也有它設(shè)計(jì)上的錯(cuò)
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.
這門語言的整體設(shè)計(jì)(上的問題)是相當(dāng)明顯的。奇怪的是ECMAScript委員
Lousy Implementations
糟糕的實(shí)現(xiàn)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的一些早期實(shí)現(xiàn)有許多bug
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書都是相當(dāng)可怕的。它們包含錯(cuò)誤
Substandard Standard
“準(zhǔn)標(biāo)準(zhǔn)”的標(biāo)準(zhǔn)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公布的官方語言規(guī)范的質(zhì)量極其的差。不僅難讀而且極其難懂。它可為那些"糟糕的書
Amateurs
業(yè)余者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的人大多不是程序員,他們?nèi)鄙賹懥己贸绦虻?WBR>培訓(xùn)和訓(xùn)練。JavaScript有非常強(qiáng)大的表現(xiàn)力
Object-Oriented
面向?qū)ο?/SPAN>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是面向?qū)ο蟮膯??它有?duì)象,它的對(duì)象可以包含
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.
構(gòu)建對(duì)象系統(tǒng)的兩大主要方法是繼承(is-a)和聚合(has
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.
一些關(guān)于JavaScript不是真的面向?qū)ο蟮臓?zhēng)論其理由是它沒
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.
但是事實(shí)是JavaScript 的對(duì)象可以有私有變量和私有方法(點(diǎn)擊這里來看如何實(shí)現(xiàn))。當(dāng)然,之所以很少有人知道這個(gè)是因?yàn)镴avaScript是世界
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.
另一些關(guān)于JavaScript不是真的面向?qū)ο蟮臓?zhēng)論其理由是它沒有提供繼承。但是事實(shí)是JavaScript不但支持經(jīng)典的繼承,而且支持其他一些代碼重用的模式。
覺得這篇文章很不錯(cuò),轉(zhuǎn)載過來與大家一起分享.
英文地址:http://www.crockford.com/javascript/javascript.html
中文翻譯地址:http://blog.csdn.net/uoyevoli/archive/2006/05/19/744915.aspx 譯者:袁曉輝
相關(guān)文章
js動(dòng)態(tài)創(chuàng)建表格,刪除行列的小例子
這篇文章介紹了js動(dòng)態(tài)創(chuàng)建表格,刪除行列的實(shí)例代碼,有需要的朋友可以參考一下2013-07-07微信小程序 高德地圖路線規(guī)劃實(shí)現(xiàn)過程詳解
這篇文章主要介紹了微信小程序 路線規(guī)劃實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08使用CoffeeScrip優(yōu)美方式編寫javascript代碼
CoffeeScript就是JavaScript,他進(jìn)行的是一對(duì)一的編譯,或者說是翻譯,而且編譯成的JavaScript代碼可讀性很強(qiáng)。本文給大家介紹使用CoffeeScript優(yōu)美方式編寫javascript代碼,感興趣的朋友一起看看吧2015-10-10JS遍歷JSON數(shù)組及獲取JSON數(shù)組長(zhǎng)度操作示例【測(cè)試可用】
這篇文章主要介紹了JS遍歷JSON數(shù)組及獲取JSON數(shù)組長(zhǎng)度操作,涉及javascript簡(jiǎn)單json數(shù)組遍歷與運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2018-12-12javascript日期驗(yàn)證之輸入日期大于等于當(dāng)前日期
這篇文章主要介紹了javascript日期驗(yàn)證之輸入日期大于等于當(dāng)前日期,需要的朋友可以參考下2015-12-12從js向Action傳中文參數(shù)出現(xiàn)亂碼問題的解決方法
Action獲取jsp表單中的中文參數(shù),只要整個(gè)項(xiàng)目都采用UTF-8編碼格式都不會(huì)出現(xiàn)亂碼問題;但JSP中用到JS,并從JS向Action傳中文參數(shù),就會(huì)出現(xiàn)中文亂的現(xiàn)象2013-12-12詳解GoJs節(jié)點(diǎn)的折疊展開實(shí)現(xiàn)
這篇文章主要為大家介紹了GoJs節(jié)點(diǎn)的折疊展開實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05Bootstrap基本插件學(xué)習(xí)筆記之輪播幻燈片(23)
這篇文章主要為大家詳細(xì)介紹了Bootstrap基本插件學(xué)習(xí)筆記之輪播幻燈片的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12