User:Shaver/ES4 FAQ

From MozillaWiki
Jump to navigation Jump to search

What is ES4?

ES4 (ECMAScript, 4th Edition) is the name that will be given to the next revision of the ECMAScript language, the standardized basis of JavaScript and other similar languages. In this document, "ES4" refers to the current working draft, which is expected to be completed and ratified by ECMA near the end of 2008. An overview of this draft, including motivations for many of the design choices, is available here (XXX).

ES4 represents a significant and powerful evolution of the ES3 language, which preserves compatibility with existing programming models and "legacy" code while adding new, optional capabilities to support larger scale programming. It borrows capabilities and techniques from languages such as ActionScript and Python while making them fit with the spirit and existing practice of ECMAScript as used on the web and elsewhere over the last decade.

In addition, as with previous editions of ECMAScript, ES4 contains a number of bug fixes (XXX) to make the specification fit better with deployed behaviour and developer expectation, and repair plain errors in the specification text.

If browsers implement ES4, will it break my existing scripts?

Almost certainly not.

The ECMA committee chartered to develop and maintain the ECMAScript specification, known as "TG1", has taken compatibility with existing scripts as their number one priority. The vast majority of features in ES4 which could conflict with, or change the meaning of, existing ES3 (JS1.x) scripts aren't available unless the script author explicitly opts into them.

There are several categories of changes introduced in ES4 which can affect existing ES3 code:

  • opt-in facilities such as new keywords, which will not affect programs unless the new ES4 capabilities are explicitly requested
  • bug fixes to match prevailing (often: all) browser support, such that the specification better reflects what developers can actually expect from implementations; programs that run in the real world today will be unaffected, obviously, as this is codification of existing practice
  • bug fixes to match user expectation, where the ES3 behaviour was a trap for the unwary, and not useful in its specified form; the classic example is how this is bound in nested functions, which is one of the most confusing and anger-inducing defects in the ES3 specification.

A complete description of all incompatibilities between ES4 and ES3 (as specified; note again that many of the changes represent codification of what is actually implemented in virtually all engines) is available at XXX.

Do I have to upgrade all my script to ES4 at once?

No.

Significant effort has gone into ensuring that ES4 code and ES3 code can interoperate simply, including preservation of argument types and values when ES4 values pass through ES3 functions and scripts. You can upgrade your code piecemeal as you need and want to use new ES4 capabilities, and don't need to give up your existing ES3 libraries or application code to do so.

Who is designing ES4?

The ECMA TG1 committee has as member companies Adobe, Apple, Opera, Mbedthis, Microsoft, Mozilla, and Yahoo!; of these, all but Apple have been active in the ES4 process over the past two years, with Apple joining the committee activities much more recently. Since April 2007, Microsoft and Yahoo! have registered their opposition to the current draft, and The current draft specification is opposed by Microsoft and Yahoo!, and they have not contributed significantly to the specification since that time. The dissenting members of TG1 have indicated that they believe the current draft proposal to As of this writing, there is no alternative proposal from Microsoft and Yahoo! for review by TG1, though they have indicated that they are working on one.

In addition, there are several invited experts in the fields of type theory and programming language design who participate actively in the design of the language and have helped tremendously in the production of what the majority of committee members believe is a robust specification.

Will ES4 require me to specify types, or stop changing the properties of my objects dynamically, as I do today with ES3?

No.

Even if an author opts into ES4's syntax-incompatible features as mentioned above, it's still up to them to use types, various "fixed binding" features such as classes and intrinsics, and any other ES4 feature as they choose. All the dynamism of ES3 is still available to script authors, but they will now also have options for reducing that dynamism or placing restrictions on how their code can be used, in order to improve security, performance, and reliability of their applications.

Are there implementations of ES4?

There are no complete implementations of ES4 as of this writing. The TG1 committee is building a reference implementation in parallel with development of the specification, as a means of proving out various design decisions and providing a tool (albeit a slow one) for developers to use in testing the language and specification. This reference implementation, though still incomplete, is being actively used by developers within and outside TG1 to test elements of the language and ensure compatibility with existing ES3 script.

The Tamarin project is another open-source ES4 implementation, which is being developed chiefly by Mozilla and Adobe for use in future Firefox and Flash Player products. There may be other ES4 implementations underway internal to different organizations, as well.

When can I realistically start using ECMAScript 4?

It depends within which context. If you are most concerned with doing web development using ECMAScript 4 (and, thusly, JavaScript 2) then the short answer is: Probably sometime in 2009.

There's multiple aspects to this response and it can be broken down as such:

Mozilla is working hard to create a full implementation of JavaScript 2. This will be created using Tamarin and integrated into the Mozilla platform via ActionMonkey. This is part of the large Mozilla 2 rewrite and will be introduced, to the general public, in Firefox 4 (which will, most likely, be released in 2009). Right now, however, you can begin using some JavaScript 2 features in the current release of Firefox (Firefox 1.5 has JavaScript 1.6, 2.0 has 1.7, and 3.0 has 1.8).

Opera has already begun some implementation of features in the upcoming Opera 9.5 browser. It is expected that they will have a large portion of ECMAScript 4 implemented by 2008-2009.

Apple has not outlined any specific plans for implementing ECMAScript 4 in Safari (in KJS). However, they have recently joined the ECMAScript group and are tracking the development of the language.

Adobe has been making significant headway towards building a full ECMAScript 4 implementation. Currently, ActionScript 3 implements a large portion of the ECMAScript 4 specification. However, for ActionScript 4 they are looking to move to a full ECMAScript 4 implementation. Adobe is working with Mozilla to build up the Tamarin virtual machine - which should be embedded in Adobe Flash 10.

Microsoft has not announced any specific plans about implementing ECMAScript 4 in Internet Explorer, other than comments in TG1 meetings indicating that they would implement it after IE7. Their implementation of JScript.NET 8 already has some ECMAScript 4 features in it. It isn't clear, though, if they will be working to bring JScript.NET in line with the full specification.

All of that being said, there's an important development taking place: ScreamingMonkey. ScreamingMonkey is a Mozilla project that is attempting to integrate the Tamarin engine into Internet Explorer, allowing users to develop JavaScript 2-compatible applications that'll work in all browsers. To complete the picture, it is expected that Adobe will help to distribute ScreamingMonkey with the Flash runtime - providing browser-based JavaScript 2 support to all users that have Flash installed.

How can I try ECMAScript 4?

The ECMAScript working group (ECMA TG1) is providing a reference implementation that you can play with in order to get a feel for how the language operates. A binary version currently exists for OS X. This download will give you a console application that you can run to try the syntax out for yourself.

You can use the binary reference implementation like so (on OSX and Linux):

$ ./es4
>> var test = "works!";
>> var test2: int = 5;
>> class User { var name; }
>> var u = new User();
>> u
[object User]
>> u.name = "John";
John

The reference implementation was created for ECMAScript 4 implementors to use as a base of comparison for their development. Thus, it's implemented using SML (a language well suited to building language references). That being said, it still makes for a great resource from which testing and exploration can be done.