ECMAScript 6 returns JavaScript to original intent

The committee behind ECMAScript wants a quicker release schedule to keep up with the pace of Web innovation

OMG JavaScript
Flickr/Andy Piper

The TC39 committee at EMCA International, responsible for developing the ECMAScript specification that provides the basis for JavaScript, is working on parallel versions of ECMAScript -- versions 6 and 7. Committee member Jafar Husain, cross-team technical lead for UIs at Netflix, talked about what's coming up for ECMAScript at this week's HTMLDevconf event in San Francisco and sat down with InfoWorld Editor-at-Large Paul Krill to elaborate on where JavaScript is headed.

Jafar Husain

Jafar Husain, TC39 committee member at EMCA International

InfoWorld: When are the planned arrival dates of ECMAScript 6 and 7?

Husain: The ES specification for 6 is planned to be finalized, I think, June 2015. ES 7 currently has no date of arrival, but the committee members have talked about a more regular cadence, and certainly I think you'll see that release for ES 7 is quicker than the one for ES 6, which is a very, very large release because it was so long overdue.

InfoWorld: Why the parallel development?

Husain: First and foremost, because it's a good idea. Parallel development allows us to design features with foresight because we can't do everything in one release. Knowing about what we plan to do in ES 7 will allow us to put in the groundwork in ES 6 and then [use] the same process going forward. But also simply because we want to be more responsible. The Web community moves so quickly and people are doing so much innovation that years and years of releases between JavaScript versions is not acceptable.

InfoWorld: Would you say ECMAScript 6 and 7 are about making ECMAScript, and by extension JavaScript, a far more sophisticated language?

Husain: I would characterize the ECMAScript 6 language in many ways as being true to JavaScript, truer to JavaScript as it was originally designed by Brendan Eich.

One of the unfortunate realities is that JavaScript was originally a very different-looking language. In fact, when Brendan Eich submitted it to Netscape, it had a completely different syntax, and for a variety of business reasons, Netscape, at the time partnering with Sun, told Brendan Eich to basically make it look like Java. When you do language design, it's really about picking your core idioms, and in the case of JavaScript, one could arguably say that was structural types, prototype inheritance, and closures; then, once you pick those core idioms that you hope are orthogonal and work well together, you design a syntax to make it easy to use those idioms.

Unfortunately, JavaScript's idioms have Java syntax, and Java has none of the three idioms I just said. That made JavaScript painful to use. When a language is so dependent on closures, having to type 26 characters to create a function is ridiculous. In many ways what we're doing, I think first and foremost with the sugar, the syntactic sugar in JavaScript 6, is actually creating syntax that makes it easy to use the idioms already in the language.

InfoWorld: Would you say async programming is the main feature planned in ECMAScript 7?

Husain: I don't know that I would say that. There are a lot of proposals in ECMAScript 7. The reality is that JavaScript, in many senses, serves two masters. It serves not just practitioners using JavaScript directly, but it serves compilers. I completely left out of my talk a huge number of features that are being introduced to make JavaScript a better compilation target for other languages. You could compile TypeScript into JavaScript or Dart into JavaScript and so on and so forth.

I don't think it's fair to say that async programming is the main focus. I would like it personally to be a large focus, and some of the proposals that I've put forward with representatives from Mozilla do a lot to make async programming easier, but it's very early in the stages, and there's no reason to believe that these are going to get rubber-stamped and go through. They might be too big and have to wait for ES 8, or they might never get accepted. Currently async functions are for ES 7, and async generators I'm proposing for ES 7.

InfoWorld: Explain the difference between async functions and async generators.

Husain: A function returns a value. The thing about a function is the consumer is in control. The consumer calls a function, and the world blocks until that function returns the value. Now an iterator is, basically, think of it as a function that can return multiple values. The consumer asks for an iterator, then pulls by calling next, pulls values out. Now in a reasonable time, the consumer requests a value, again everything blocks and the world stops until that consumer gets their value. I call it synchronous programming.

An asynchronous function is being proposed for JavaScript 7, and what it does is it pushes a value to the consumer. The consumer calls the function, but they get out a promise, then they register a callback with that promise, then the producer of the value, the function itself, pushes the value into their callback by invoking their callback….

The truth is JavaScript's async, whenever it does things like I/O, it has to be async. JavaScript doesn't have a choice. That's what differentiates it from many other languages like C# or Java. To the developer, what it means is that instead of async programming becoming very, very complicated and the code that they write to create async functions looking very, very different, the code that they write, now we can make, whether a function is async or not, just a detail. You add a little more syntax, but the code basically looks the same.

InfoWorld: So it makes it easier for developers to do async programming?

Husain: You said it shorter than I did, but yes.

InfoWorld: Which important features of ES 6 and 7 have already been implemented in browsers?

Husain: ES 6 has had a lot features [that have] already made their way into browsers. I think Mozilla, with Firefox, is the most ahead of the game. I'm going to forget a few here, but destructuring, fat arrows, generators are in Chrome behind an experimental flag. I'm just talking about JavaScript 6 at the moment.

I believe Firefox has implemented let, which is the replacement for var. Proxies made their way again into an experimental flag in Chrome. Generators are also in Firefox, incidentally. My recollection is that Internet Explorer is going to really start aggressively rolling out some ES 6 features in the near future. ES 7, as far as I am aware, the only feature that's made its way into a browser thus far is Object.observe, a feature that allows you to use any native JavaScript object without having to go through a special setter or a getter but allows you to track changes to that object.

InfoWorld: Intel has been promoting the speed of JavaScript applications by supporting inclusion of SIMD in ECMAScript. What has been the progress of this effort?

Husain: Certainly, my perception is that there's broad support for SIMD, and I think Intel has very impressive demos that show that SIMD performance can dramatically improve rendering. I think the committee is generally supportive of anything that's going to improve the speed of the Web, and it certainly looks like SIMD is a good choice.

InfoWorld: A developer of the Ceylon language told me that JavaScript is inferior for building large applications. How would you respond to that?

Husain: He might be saying that for a whole variety of different reasons. I'll tell you one reason why people say JavaScript is not a good language for building large applications: It is not statically typed. I can tell you that there are people on the committee who would like to add types to JavaScript, and there are probably people on the committee who would rather anything happen but types be added to JavaScript.

Personally, I think it's quite possible to build large applications in JavaScript, mostly because people are building large applications in JavaScript. I can tell you that there are now two options [for types in JavaScript]. One is TypeScript, which Microsoft releases and that is essentially just JavaScript plus types. Facebook also has a framework, Flow, which is very similar to TypeScript and it again adds types to JavaScript.

InfoWorld: Is Brendan Eich still involved in the development of JavaScript with the ECMA committee?

Husain: He's involved day-to-day in the development of JavaScript.

Copyright © 2014 IDG Communications, Inc.

How to choose a low-code development platform