OdeToCode IC Logo

ECMAScript 4 – Kitchen Sink Included

Tuesday, November 13, 2007

Ajaxian linked to a reference implementation of ECMAScript 4 today. ECMAScript 4 (a.k.a JavaScript) is still a work in progress. When the work is finished, the new standard will be the first major update to the language since 1999.

The language overview whitepaper is 40 pages of ambition – iterators, pragmas, packages, namespaces, serialization, generics, annotations, non-nullable variables - and the list goes on.

Here is some code I was toying with:

interface Printable {
    function print()

class Point implements Printable {

static var name = "Point class";

private var _x : int;
private var _y : int;

    function get x() {
return _x; }
    function set x(value:
int) { _x = value; }
    function get y() {
return _y; }
    function set y(value:
int) { _y = value; }

    function print()

Here is the code running in the reference implementation:

PS> .\es4
>> intrinsic::load('Point.es4')
>> var p = new Point();
>> p.x = 10;
>> p.y = 15;

Note that the following lines will create errors:

>> p.foo = "error: cannot add property to a non-dynamic object";
>> p.x = "error: incompatible types";

Wow! This is not the small, dynamic language that I've grown fond of this year. JavaScript is everywhere now – and I wonder how long it will take the various implementations to work out all the kinks in this standard.

ECMAScript is going from 0 to C++++ in a single release.