ES6, ES7, and Looking Forward

Posted on by in Development, Everything Else

After attending Allen Wirts-Brock’s presentation on ES6 and ES7 at ForwardJS last week, I asked him if there was more momentum in shaping the JavaScript language recently. ES6, or ECMAScript 2015, has only just been released and shall soon be followed by ES7, or ECMAScript 2016. And what is ECMAScript, you may ask? ECMAScript is nothing more or less than the standard that defines what JavaScript is. With the last major release of ES5.1 back in 2011, and two new releases two years in a row, it appeared to me there was new momentum put into evolving this incredibly popular language. This blog will give you an overview of how JavaScript is being shaped over time and give a high-level look at ES6 and ES7.

Shaping JavaScript

Allen famously created the JavaScript language with Brendan Eich in just 10 days in May of 1995. He points out that while that statement is true, the reality is that there was a lot of thought preceding those 10 days about how the language would be shaped. After initially creating the language, it was picked up by two different companies who were trying to develop it independently. That is when the standards committee was developed. Technical Committee 39 (TC-39) of ECMA International now sets the ECMAScript standard. The standards committee is headed by pioneers in the business: Mozilla, jQuery, Meteor, Salesforce, Internet Explorer, Intel, et al.

As Douglas Crockford famously said, “JavaScript has some extraordinarily good parts.” However, Allen admits there’s a whole lot of baggage with the language. Later iterations of JavaScript have all been created to build upon previous successes and minimize the problematic parts of the language. Just eliminating the problematic parts is unfortunately not an option — you need to remain backwards-compatible. Fundamentally, you can’t break the web.

ES6 & ES7

Things TC39 focused on for ES6.

  • Modularity
  • Better abstraction capability
  • Better functional programming support
  • Better OO support
  • Expressiveness and clarity
  • Better compilation target
  • Things that nobody else can do.

Certain things on this list are fairly straightforward — modularity, for instance. For better OO support, classes, which are a bit of a problem in JavaScript, essentially just have a better format. ‘Things that nobody else can do’ is broad, but I will say I’m excited to play around with generators. Expressiveness and clarity can be seen in random new features here and there like the spread operator “…”, which incorporates any remaining parameters passed in into a single item, multiple ways to define a function, and better declaration rules. Better abstraction capability can be seen in the ability to create iterators that don’t just respond to arrays, but other data structures as well.

With these focus points in mind, they looked at some of the areas they could improve. As an example, one of the areas they worked on was hoisting, which is JavaScript’s default behavior of moving all declarations to the top. Hoisting has historically caused problems and TC39 wanted to redefine var so it doesn’t have this hoisting problem, but again, don’t break the web. They couldn’t change existing functionality. Instead they added a let, a type of declaration that doesn’t get hoisted to the top of the function. This now means each time you’re capturing the closure, you capture the let in that block as well.

For the next iteration, ES7:

  • new array function: [“a”, “b”].includes (“b”) // true
  • exponentiation operator: 3 ** 2 //9, the exponentiation operator

Missed for this coming release (maybe the next?):

  • async functions
  • SIMD support
  • String padStart padEnd

Next Wave

So, now that the standards are released, when do we get to play with the new features? Once the the browsers incorporate these changes into their next release. Some have already been incorporated, such as number and array functions in Firefox. Others like let will take a while. For now, you can use ES6 with a transpiler, which will take your code and compile it into ES5 for you. We personally use the sprockets-es6 gem for this task in Rails, but there are many others options including using Babel directly for Node.

And as for momentum, they’re right now targeting yearly releases, which was reflected in the new names of ECMAScript 2015 and 2016 for ES6 and ES7. In the past, activity on the ECMAScript standard has been low, followed by a big burst which resulted in a lot of features and, like all big releases, was hard to get out. The yearly releases are an effort for a more balanced and continuous approach. When I asked Allen about all the new sudden energy, he said that all these changes were in the works for a while. I asked if it was a culmination of all the effort put in over the years. He responded that it was more like the start of the next wave of JavaScript.