JavaScript:世界上误解最深的语言

javascript

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.

JavaScript,或者叫 Mocha,或者叫 LiveScript,或者叫 JScript,又或者叫 ECMAScript,是世界上最流行的编程语言之一。事实上世界上的每一台个人电脑都安装并在频繁使用至少一个JavaScript解释器。JavaScript的流行完全是由于他在WWW脚本语言领域中的地位决定的。

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是另外一种语言。

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更好。

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,嗯……还是这个名字好。

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后缀让人认为他不是一门真正的编程语言,和一门"编程语言"还有相当的差距。但是这只是应用领域的问题。和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

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委员会,这门语言的管家,正在对它进行扩展,也在蓄意恶化它最大的问题:有太多的版本。这是混乱的根源。

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应该为此感到非常尴尬。

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一个”全然适合业余爱好者而不适合专业程序员“的名声。这很明显是一个错误。

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都有,但是它的动态天性允许有比聚合更好的实现方式。

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不但支持经典的继承,而且支持其他一些代码重用的模式。

Copyright 2001 Douglas Crockford. All Rights Reserved Wrrrldwide.

版权所有

原文链接:http://www.crockford.com/javascript/javascript.html

时间: 2024-10-02 18:51:50

JavaScript:世界上误解最深的语言的相关文章

JavaScript-世界上误解最深的语言分析_javascript技巧

JavaScript,是世界上最流行的编程语言之一.事实上世界上的每一台个人电脑都安装并在频繁使用至少一个JavaScript解释器.JavaScript的流行完全是由于他在WWW脚本语言领域中的地位决定的. Despite its popularity, few know that JavaScript is a very nice dynamic object-oriented general-purpose programming language. How can this be a s

世界上没有完美的编程语言, 不要和一种语言厮守终生

简评:就像段子中说的那样,如果你想爆发一场程序员之间的世界大战,只需要发一句"PHP是最好的语言"就可以了.其实对于程序员而言,往往喜欢给自己打上"Java程序员"."PHP程序员"或者"OC程序员"的标签,并且对于什么才是最好的语言争论不休,甚至者更有"程序员鄙视链"链式地鄙视下去,但是其实世界上本没有完美的编程语言,当你在处理某些领域的问题时往往需要换一种语言,语言只是解决问题的工具,仅此而已.编程语言

揭秘用“世界上最好的编程语言”制作的敲诈者木马

背景 你永远叫不醒一个装睡的人.但,快递小哥可以! 虽说是一句戏言,但确实多少反映出了快递在大家心中的重要性.如果你收到一个带有快递公司发来的电子邮件通知,你会不会也希望快点打开看看是不是哪个朋友给你寄了什么东西等着你去取呢?最近我们就收到了这样的一个带有"快递单号"的电子邮件附件.唯一有些水土不服的就是--在中国用FedEx的确实并不很多--大写的PITY-- 木马起始--FedEx_ID_00645987.doc.js 这个所谓的doc文档,其实是一个javascript脚本,而脚

喜马拉雅天梯:双11、互联网和快递改变世界上海拔最高之地

珠穆朗玛,世界第三极--青藏高原的极点. 离这个极点最近的扎西宗乡人,大概是这世界上,除了高原地质专家.气象学家.神话学者和登山家外,最了解世界最高峰所有秘密的人了. 珠峰脚下的扎西宗乡 生活在珠峰脚下的扎西宗人,与头顶的珠峰为伴,从生到死,从白昼到黑夜.他们知悉神山的一切:它的不可抵达,它的神秘与日常,它的多变与无常. 过去,神山庇佑扎西宗人的灵魂.现在,在灵魂之外,围绕神山诞生的旅游.科考和商业活动,也在逐渐让它脚下的子民缓慢进入到一种新旧夹杂.铁板不再一块的生活状态. 这种状态,犹如冰川和

JavaScript正则表达式上之基本语法(推荐)

相关阅读: js正则表达式基本语法(精粹) 正则表达式语法 一个正则表达式就是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式.该模式描述在查找文字主体时待匹配的一个或多个字符串.正则表达式作为一个模板,将某个字符模式与所搜索的字符串进行匹配. 定义 JavaScript种正则表达式有两种定义方式,定义一个匹配类似 <%XXX%> 的字符串 1. 构造函数 复制代码 代码如下: var reg=new RegExp('<%[^%>]+%>','g')

【转】Nero v9.4.26.0 多语(简体中文)版+完美破解(世界上最多人使用的烧录软体)

为流动影音媒体技术的创造者,Nero 允许随时随地在任意设备上创建和分发流动影音媒体内容.公司开发不依赖于独特平台的.基于标准的解决方案,让用户可以不用再考虑硬件和文件格式,自由地欣赏他们的音乐.照片和视频. 如今,全球有超过三亿的家庭.移动和专业用户在使用Nero屡获大奖的软件解决方案.Nero 还为战略合作伙伴提供可用于各种最新平台和设备的应用程序.编解码器.工具.软件开发套件和编程接口.Nero 通过硬件制造商.国际合作伙伴.零售商或直接通过官方网站的网上商店在全球分发产品.中文名称:Ne

这个世界上所有的人,并不是个个都有过你拥有的那些优越条件(转)

保证开发人员:"目标清晰,职责明确,赏罚分明,超越伯乐"(参考道哥的专栏).现在和开发人员不在一块办公,导致彼此之间交流比较费劲,所以每周至少在一块共同办公一天时间.对外交流:<伟大的盖茨比>中有一句话,我年纪还轻,阅历不深的时候,我父亲教导过我一句话,我至今还念念不忘."每逢你想要批评任何人的时候,"他对我说,"你就记住,这个世界上所有的人,并不是个个都有过你拥有的那些优越条件"所以,自己对外交流的耐心必须增加,理解业务对于系统知识

两韩国少年成为世界上写短信最快的人

裴英浩和河木敏(右). 据新华社报道 手机短信你能写多快?相信你一定快不过韩国人裴英浩和河木敏. 最近在美国纽约举行的"移动世界杯"决赛中,18岁的裴英浩和17岁的河木敏力克12国对手,一举夺魁,赢得"世界上写短信最快的人"称号. 美国队和阿根廷队分别获得第二名和第三名. "移动世界杯"由韩国LG公司赞助,比赛规则很简单:用自己的母语写短信,看谁写得又快又准. 比赛时,选手需要用手机输入大屏幕上提示的字句,必须保证与原文一致,不许使用缩写,不许发

世界上最好的目录索引工 dirhtml 4.56 提供下载了_常用工具

世界上最好的目录索引工具!完全免费!有了它,那些文件夹及目录索引的软件都可以扔一边了.这是我逛国外网站时无意中发现的,刚下载下来时打开一看,软件其貌不扬,甚至称得上是恐龙级的丑,而且界面有好多文字都重叠,真不知道作者设计时是怎么想的,当时就想一扔了之,可冲着它的名字 dirhtml ,我还是玩了一阵子,这一玩不要紧,玩得是越来越爱,竟产生了把它汉化的冲动."幽兰在深谷,寂寞无人知",可见世界上有多少金子都是埋在沙砾中的.大街上一眼望去,平凡如我者多,即使你是金子,别人也会把你当成沙子,