About David Hammond

David Hammond is a professional Web developer who focuses heavily on Web standards and accessibility. He runs the Web Devout website, which provides useful resources for Web developers and has been featured in several Web development books around the world. Since 2006, he has served as the resident Web developer for the California Community Colleges Technology Center.

Web Principles: ECMAScript, Fifth Edition Now A Standard

The fifth version of ECMAScript has now been finalized and published as an Ecma International standard. ECMAScript, which is more commonly known as "JavaScript", is the programming language that provides for much of the interactivity in modern web applications. This is the first major new version of the language since the third edition, which was published in December 1999.

When people refer to "JavaScript", it's usually ECMAScript they're talking about. Firefox's extended ECMAScript implementation is called "JavaScript" (although it is completely unrelated to the Java language), and Internet Explorer's implementation of ECMAScript is called "JScript". Other browsers tend to use the terms ECMAScript and JavaScript interchangeably. ECMAScript itself is the core standard on which each browser's scripting support is based.

Over the last decade, there has been an increasing need to improve the ECMAScript language in order to better meet today's needs. The drafting process for the fouth edition saw ambitious plans to overhaul much of the language and bring it closer to traditional "classical" object-oriented languages like C++ and Java. However, there was a great deal of controversy over the nature and scope of these changes, and the fourth edition was eventually abandoned.

In contrast, the fifth edition just aims to make incremental improvements to the language. The developers wanted to keep it true to its heritage, maintaining the emphasis on the Self-like prototypical object-oriented model (as opposed to the classical C++/Java model), and simply making the language better at what it does.

One of the interesting additions is a new "strict" mode, which, when enabled in the script, removes some problematic legacy aspects of the language and provides a bit more enforcement of best practices. This was the brainchild of Douglas Crockford, and it more or less makes his JSLint product a native part of the ECMAScript language.

As another example of Crockford's influence, ECMAScript, Fifth Edition also contains native functions to convert between JSON strings and native objects. JSON, which stands for JavaScript Object Notation, is a popular data format formalized by Crockford. It provides a straight-forward way to pass simple object data structures from one application to another or across programming languages. The data structure is encoded as a portable string that looks just like the source code you would use to create it in many C-style programming languages (ECMAScript included).

Perhaps the most useful new features are the more complete object property controls. It's now possible to define getters and setters for properties (also known in other languages as "overloaded" properties), and to set properties as unwritable, non-enumerable (meaning they don't show up when iterating over the object's properties), and non-configurable (meaning these property traits are locked down). Entire objects can be set to "prevent extensions," meaning new properties can't be added to the object; "sealed," meaning all of the object's property traits are non-configurable; or "frozen," meaning all of the property values are locked down as well. These features will allow web developers to program the same kinds of rich APIs and access controls in their own objects that we're all used to seeing in the browser-provided DOM objects.

Other changes include a number of long-overdue additions to the standard library, such as the "bind" function for setting the context of a function, a "trim" function for strings, and the "JavaScript Array Extras" array methods that most browsers have supported for a long time (including the ever-important "indexOf" function which Internet Explorer still doesn't support). That said, I would have liked to see them add a lot more, since I feel that the small and somewhat patchy standard library is one of ECMAScript's weakest points.

While many of these features are already supported in the latest versions of some browsers, it will still take a few browser generations before it is safe to rely on them. One nice aspect of ECMAScript's design is that it's usually easy for the script to test which features the browser natively supports and to dynamically extend the language with custom ECMAScript code when needed. ECMAScript, Fifth Edition is designed to be syntactically compatible with ECMAScript 3, which means that you won't have to completely shun older browsers in order to make use of the newer features.

Here's a link to the ECMAScript website, which contains links to the new specification and the latest press release: http://www.ecmascript.org/  <>

Add comment