ES6 + ES7, EcmaScript 2015 -- Harmony .. WHAT? @ nodeconf 2015
JavaScript gets a new version, what now
Languages are never done. They evolve over time and are supplemented with new words every month, new phrases every year and acquires (minor) grammar changes every decade. This true for speaking languages as well as for programming languages.
The past year there has been a lot of talk about EcmaScript 6 (a.k.a. ES Harmony, or lately ES2015, which is the silliest name of all). A set of features that is coming, or has already landed for JavaScript. ES6 is nothing more than a specification of features according to Mikeal Rogers. A specification of features that have been designed, but are not certain to land in the coming years. Some of them are just syntactic sugar (classes,9 , that don’t add anything new. Some are hurting performance and some are just plain great.
In the node community there has been some commotion surrounding ES6 because most of the features were suddenly being implemented in a fork of node called “io.js”. The temporary fork and squabble that is/has been (depending on when you read this) “io.js” was mainly to move node forward and out of a corporate governance model to a more open model. But you should just read some article explaining that.
If you want to play around with these features, you either have to wait for some of the features to be implemented (in browsers and node.js alike), or you need a transpiler or polyfill framework, for backwards compatibility or even to run it because no one supports it yet… Most people are using Babel which has a very decent set of docs and examples and transpiles your code back to ES5.
The thing that excites me most is the native promise implementation and the generators.
Then some people were really enthusiastic about an ES7 proposal for asynchronous functions: async
. If a function is async, you just “tell” the VM by doing this (example taken from the async proposal):
async function getData() {
var items = await fetchAsync('http://example.com/users');
return await* items.map(async(item) => {
return {
title: item.title,
img: (await fetchAsync(item.userDataUrl)).img
}
});
}
Take note of the async
and the await
keywords.
One of the workshops at nodeconf was also about ES2015. It gives an overview of most features and you can play with the examples.