Object JavaScript – ECMAScript 6 Futures Overview

imageECMAScript 6 specification and implementation is underway and promises to bring many of the features that you’ve learned about in the posts on Object JavaScript. ECMAScript is the foundation of JavaScript. ECMAScript has gone through several versions. The current browsers support ECMA Script 5. . The discussions today are revolving improvements beyond versions past 5, which are code-named, ECMAScript Harmony.

The ES6 compatibility table is very useful, as it tells us the ES6 features that are supported in the current browser. It also gives us a handy link to the specifications for each of the features listed.  You will find that the current versions of browsers are implementing these features as fast as they can. The table shows that some subset of the feature exists, so as we say,  “your mileage may vary”. That said, it is coming.

I don’t have any particular insider information, but wanted to share what I am learning as I explore ECMAScript 6 and what it means to the way that code is written today. In my search I found two great articles that I am pulling information from:

My value add is to provide context for the previous posts and show how your code in the future could look like to implement many of the same features. And this topic is fluid so again, “your mileage may vary”. My intent is to give you can idea of what is coming and how soon to help you decide how deeply you want to invest in the current technologies. That said, one of the goals in ECMAScript 6 is to not break anything you are doing now.

Overview

ECMAScript includes goals to make JavaScript better:

  • For complex applications
  • For libraries (including the DOM)
  • As a target for code generators

ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side scripting on the web, in the form of several well-known implementations such as JavaScript, JScript and ActionScript.

The design is by a couple experts with feedback from TC39 and the web community. There’s lots of field testing and browser, compiler manufacturers are on board building features and developers are trying them out. You too can get started.

Actual versions of draft you can find here: http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts.

General Timetable

The ES specification for 6 is planned to be finalized, I think, June 2015. ES 7 currently has no date of arrival.

The feature set has been forzen. Features are appearing in the newer versions of browsers, including Internet Explorer, Chrome, and Firefox. There isn’t a lot of buzz around them because they are very much work in progress.

The specification should be finished any day now.

Publication process is scheduled for March 2015.

Formal publication in June 2015.

Backward Compatibility

Of course there are challenges with compatibility. The new version must run all existing code, which means that ECMAScript 6 includes only new features.

Major New Features

  • const
  • let (global scope)
  • let (local scope)
  • Destructuring assignment
  • for…of statement
  • Iterators and generators
  • Default parameters
  • Spread operator of Array
  • Arrow functions
  • Array comprehensions
  • Promises
  • Better support for Unicode (strings and regular expressions)
  • Optimizing tail calls
  • Proxies

Will explore in the next post.

What’s Happening with Modules?

ES6 Module Transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the ES6 module syntax, and compile it into AMD or CommonJS modules. This compiler provides a way to experiment with ES6 syntax in real world scenarios to see how the syntax holds up. It also provides a nicer, more declarative way to write AMD (or CommonJS) modules.

ES6 Module Loader Polyfill that is based on ES6 for Node.js and for browsers with some

Shims for ES6 Promises. Q.Promise is compatible with ES6.

TypeScript

TypeScript is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript.

There are several overlaps and complimentary features between TypeScript and ECMAScript 6. The team is aligning TypeScript with ECMAScript. You can follow the progress on CodePlex here: http://typescript.codeplex.com/wikipage?title=ECMAScript%206%20Status

Angular

Angular 2.0 has taken a dependency on ECMAScript 6. All code in AngularJS 2 is already being written in ES6.  As ES6 doesn’t run in browsers today, the Angular teams is using the Traceur compiler to generate the nice ES5 that runs everywhere.  They are also working with the Traceur team to build support for a few extensions like annotations and assertions.  The team calls their superset of extensions “ES6 +A”.

Though AngularJS will be in ES6, you can still write in ES5 if you don’t want to upgrade.  The compiler generates readable JS and there are human-sensible analogs for the extensions.

 

References

Use ECMAScript 6 Today

ECMAScript Compatibility Table

InfoWorld: ECMAScript 6 returns JavaScript to original intent

AngularJS 2.0

Slide Deck: ECMAScript 6: what’s next for JavaScript? (August 2014)

TypeScript 1.3 and the March Toward ECMAScript 6