UserPreferences

JavaScript


JavaScript is a dynamic, untyped, interpreted language featuring a prototype-based object system (like Self or NewtonScript) with a Java-like syntax. It supports programming in imperative, object-oriented, and functional styles.

Despite its almost exclusive association with light Web-page scripting, JavaScript has a strong computer-science theoretical basis (everything is a first-class object, lexical scoping, closures, etc.). It has been described by an expert as "Common LISP with a Java syntax".

JavaScript has a very orthagonal design. The basis of the language is four types: String, Number, Array, and Function. Arrays have both list and associative functionality: it can hold an ordered list of values, or associate values with keys, or both at the same time. Objects are just arrays where "methods" are slots containing functions.

JavaScript has a prototype-based object model. JavaScript has no concept of a class (although classes can be implemented on top of prototypes)-- there are only objects. To create a new object, you copy an existing one using the new keyword. You can then modify the copy to be what you want. Objects maintain a link to the objects they were copied from (their prototypes) and use them to look up unknown methods, allowing easy inheritence. Experience shows that prototype systems are much easier for novices to understand and conceptualize, and often better for programming where "one-off" objects are common and formal hierarchies rare, such as in GUI programming.

JavaScript suffers as a programming language "in the large" somewhat due to its history as a quick solution to scripting problems. For example, if variables are not explicitly declared local they are global, and the language has no package management.

Two open source implementations of JavaScript are available from Mozilla: SeaMonkey (JavaScript in C) and Rhino (JavaScript in Java). Both allow two-way interaction between the hosting system and JavaScript (on Java this means complete access to the class library with very intelligent translation between the idioms). JavaScript as it is hosted in the Mozilla browser is also very powerful since it has access to Mozilla's DOM, XML, XSLT, and RDF engines.

There is an on-again-off-again effort at Netscape/Mozilla to define "JavaScript 2.0", which would add "in the large" features such as package management and "ints" for interoperability with other languages. Unfortunately for fans of prototype object systems, the author of the 2.0 spec derides the prototype system and plans to impose classes on JavaScript, with all the attendant complexity. It is likely that even if JavaScript 2.0 becomes a reality, fans of JavaScript "classic" will continue to use 1.5+ and may backport features such as package management.