Tuesday, December 22, 2009

EcmaScript 5 Final Spec is out

The latest spec for javascript aka EcmaScript 3.1 aka EcmaScript 5 aka Ecma-262 is out. Annex E contains a change log. Besides a long list of minor changes and spec-bug fixes, you could say the theme is "doing more with what already exists".

Strict Mode

By being in strict mode, a lot of the pitfalls in javascript can be avoided (similarly to how perl 5 works). See "Annex D" for details on the rules, but it's stuff like:

It is a SyntaxError if strict mode code contains an ObjectLiteral with more than one definition of any data property (11.1.5).

Reflection

Most of this is take what you can in a C/C++/Java version of the engine, and exposing it into the language.

Object.getPrototypeOf, Object.getOwnPropertyDescriptor, Object.getOwnPropertyNames, Object.create, Object.defineProperty, Object.defineProperties, Object.seal, Object.freeze, Object.preventExtensions, Object.isSealed, Object.isFrozen, Object.isExtensible, Object.keys,

This big one is defineProperty, it can set up getters/setters, if it's enumerable, and all sorts of other stuff.

Functional Programming

Array.prototype.every, Array.prototype.some, Array.prototype.forEach, Array.prototype.map, Array.prototype.filter, Array.prototype.reduce, Array.prototype.reduceRight,

A lot of these are in the wild already. Haven't tested the performance to see if they help, or if they are just handy.

Minor Enhancements

Array.prototype.indexOf, Array.prototype.lastIndexOf, String.prototype.trim, Date.now, Date.prototype.toISOString, Date.prototype.toJSON

Hurrah, trimming whitespace of a string is now part of javascript. How it took 10 years is a mystery.

JSON

The only new global object is to handle JSON data structures. These are in the latest versions of most browsers.

JSON.parse, JSON.stringify

What's not in

Sadly, a "Byte Array/String" is not present. Working with raw binary data is really painful right now, and having a real mechanism would open the door for all sorts of new javascript applications. boo.

In case you were wondering.

EcmaScript 4 (sometimes known as Javascript 2) died on the vine. It was very ambitious.

0 comments: