(转)JavaScript:世界上误解最深的语言
上一篇 / 下一篇 2007-10-18 14:02:37 / 个人分类:JS
Javascrīpt:
The World's Most Misunderstood Programming Language
Javascrīpt:世界上误解最深的语言
Douglas Crockford
www.crockford.com
Javascrīpt, aka Mocha, aka Livescrīpt, aka Jscrīpt, aka ECMAscrīpt, is one of the world's most popular programming languages. Virtually every personal computer in the world has at least one Javascrīpt interpreter installed on it and in active use. Javascrīpt's popularity is due entirely to its role as the scrīpting language of the WWW.
Javascrīpt,或者叫 Mocha,或者叫 Livescrīpt,或者叫 Jscrīpt,又或者叫 ECMAscrīpt,是世界上最流行的编程语言之一
Despite its popularity, few know that Javascrīpt is a very nice dynamic object-oriented general-purpose programming language. How can this be a secret? Why is this language so misunderstood?
尽管它很流行,但是很少有人知道Javascrīpt是一个非常棒
The Name
名字TheJava-prefix suggests that Javascrīpt 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. Javascrīpt is not interpreted Java. Java is interpreted Java. Javascrīpt is a different language.
Java- 前缀很容易使人联想到Java,并认为它是Java的子集或简化版
Javascrīpt 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.
Javascrīpt的语法和Java有相似之处
Javascrīpt was not developed at Sun Microsystems, the home of Java. Javascrīpt was developed at Netscape. It was originally called Livescrīpt, but that name wasn't confusing enough.
Javascrīpt不是Sun Microsystems的产品,Sun是Java的家
The-scrīptsuffix suggests that it is not a real programming language, that a scrīpting language is less than a programming language. But it is really a matter of specialization. Compared to C, Javascrīpt trades performance for expressive power and dynamism.
-scrīpt后缀让人认为他不是一门真正的编程语言,和一门"编程语言
Lisp in C's Clothing
披着C皮的LispJavascrīpt's C-like syntax, including curly braces and the clunkyforstatement, makes it appear to be an ordinary procedural language. This is misleading because Javascrīpt has more in common with functional languages likeLisp or Schemethan 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.
Javascrīpt的类C语法,包括大括号和语句的形式
Typecasting
类型转换Javascrīpt 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. Javascrīpt is theGeorge Reevesof programming languages. Javascrīpt is well suited to a large class of non-Web-related applications
Javascrīpt最初被设计成在Netscape Navigator中运行,它在Navigator中的成功引领它
Moving Target
移动靶The first versions of Javascrīpt 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.
Javascrīpt的最初几版非常弱,没有异常处理
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. Javascrīpt has its share of design errors, such as the overloading of+to mean both addition and concatenation with type coercion, and the error-pronewithstatement 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 goodlintprogram.
没有什么编程语言是完美的。Javascrīpt也有它设计上的错
The design of the language on the whole is quite sound. Surprisingly, the ECMAscrīpt committee does not appear to be interested in correcting these problems. Perhaps they are more interested in making new ones.
这门语言的整体设计(上的问题)是相当明显的。奇怪的是ECMAscrīpt委员
Lousy Implementations
糟糕的实现Some of the earlier implementations of Javascrīpt were quite buggy. This reflected badly on the language. Compounding that, those implementations were embedded in horribly buggy web browsers.
Javascrīpt的一些早期实现有许多bug
Bad Books
糟糕的书Nearly all of the books about Javascrīpt 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 Javascrīpt books, andI can only recommend one:Javascrīpt: The Definitive Guide (4th Edition)by David Flanagan. (Attention authors: If you have written a good one, please send me a review copy.)
几乎所有的Javascrīpt书都是相当可怕的。它们包含错误
Substandard Standard
“准标准”的标准Theofficial specification for the languageis published byECMA. 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公布的官方语言规范的质量极其的差。不仅难读而且极其难懂。它可为那些"糟糕的书
Amateurs
业余者Most of the people writing in Javascrīpt are not programmers. They lack the training and discipline to write good programs. Javascrīpt has so much expressive power that they are able to do useful things in it, anyway. This has given Javascrīpt a reputation of being strictly for the amateurs, that it is not suitable for professional programming. This is simply not the case.
使用Javascrīpt的人大多不是程序员,他们缺少写良好程序的
Object-Oriented
面向对象Is Javascrīpt 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.
Javascrīpt是面向对象的吗?它有对象,它的对象可以包含
The two main ways of building up object systems are by inheritance (is-a) and by aggregation (has-a). Javascrīpt does both, but its dynamic nature allows it to excel at aggregation.
构建对象系统的两大主要方法是继承(is-a)和聚合(has
Some argue that Javascrīpt 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.
一些关于Javascrīpt不是真的面向对象的争论其理由是它没
But it turns out thatJavascrīpt objectscanhave private variables and private methods. (Click here now to find out how.)Of course, few understand this because Javascrīpt is the world's most misunderstood programming language.
但是事实是Javascrīpt 的对象可以有私有变量和私有方法(点击这里来看如何实现)。当然,之所以很少有人知道这个是因为Javascrīpt是世界
Some argue that Javascrīpt is not truly object oriented because it does not provide inheritance. But it turns out thatJavascrīpt supports not only classical inheritance, but other code reuse patterns as well.
另一些关于Javascrīpt不是真的面向对象的争论其理由是它没有提供继承。但是事实是Javascrīpt不但支持经典的继承,而且支持其他一些代码重用的模式。
Copyright 2001Douglas Crockford.All Rights Reserved Wrrrldwide.
版权所有
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=744915
相关阅读:
- js事件列表 (林木森森, 2007-9-06)
- try-catch用法和含义 (feng123, 2007-9-14)
- 选中checkbox提交按钮变灰 (javy, 2007-9-14)
- (转)WEB前端开发必不可少的3大firefox插件 (xiaotian_ls, 2007-9-18)
- js cookie处理 (phperwuhan, 2007-9-18)
- Javascript集 (xiongxiaoming, 2007-9-19)
- 动态操作表格 (xiaotian_ls, 2007-10-12)
- 什麼是 JSON (ShawnFangxy, 2007-10-14)
- 双边可关闭对联广告![转] (liuxp_ping, 2007-10-18)
- Javascript中最常用的55个经典技巧 (xiaotian_ls, 2007-10-18)
TAG: JS
