JavaScript 2: An alternative proposal
The ECMAScript version 4 specification is almost ready. ECMAScript 4 will be the basis of JavaScript 2. And, omg, it’s huge! Like, literally huge. Here you can read a digest of the proposed language features.
I feel that the proposal is non-orthogonal (read: bloated) in many ways. The new language will have both class-based OOP, a la Java, and prototype-based OOP; packages and namespaces as logical units of code; static type annotations both of the nominal kind (this object IS A Thing), and of the structural kind (this object responds LIKE a Thing).
What if, instead of striving to clone Java, they focused on making ECMAScript a more pleasant language to develop in? What if they:
- added interpolated strings. Yes, I like to write
1alert("Hello, ${name}, welcome to JS!");
instead of
1alert("Hello, " + name + ", welcome to JS!"); - added a simpler syntax for passing functions as arguments. How about this:
1
2
3[1,2,3].each() do (item) {
alert(item)
}as syntactic sugar for this JavaScript construct:
1
2
3[1,2,3].each( function (item) {
alert(item)
} ); - got rid of nominal types. JavaScript can do OOP really well without classes, and it’s a shame to shoehorn classes and interfaces into it just to imitate Java and C#
- shipped a unit testing framework in the standard library
- added useful methods on arrays, like map, inject, detect, any, all
Eh? How about you? What do you wish to see in the next major version of Javascript?
Later Edit: Also see Douglas Crockford’s suggested changes.