The language we build the Web with can officially develop as fast as the Web does.
It really comes out feeling like a new language,” said Jonathan Turner, who’s recently moved from running Microsoft’s TypeScript transpiler project to Mozilla. It’s also taken the longest to develop. “While ES5 was released 6 years prior, ES2015 is the culmination of 15 years of effort that started when the committee began working on the unreleased ES4 specification around the year 2000,” explains Brian Terlson, editor of the ECMAScript standard, and a senior program manager on the Microsoft Edge team.
That adds up to a wide range of improvements with more concurrency patterns and more tools for modular design and code organization.
The two biggest new features are probably modules and classes.
“The syntax takes maybe a bit of getting used to if you come from other module systems. But once you get used to it you can work with a whole module at a time or you can work with single imports at a time and you can build one module with submodules. You can have one module that flattens that API and multiple modules that are backing it into one flat API. It allows you a lot of flexibility in how you modularize an application, how you modularize a library or how you consume a library,” Turner said.
Terlson highlights a number of other new features. “Built-in promises have paved the way for async APIs in the DOM and elsewhere to begin returning promises which is a huge boon to asynchronous programs. Generators are also key capability for certain async programming techniques and an all-around useful feature. WeakMaps give great capabilities to library authors especially.” Then there’s a host of small but significant improvements; Typed Arrays, new methods for String, Array, Number, Object and Math, new options for variables (‘let’ scopes a variable to the block you define it in) and — finally! — support for constants.
There’s also a lot of new ‘syntactic sugar’ in ES2015, from defining a function using the shortcut of typing => to the spread operator for auto-expanding arrays. Don’t be too quick to think that the style you know is best. “The various sugary features like destructuring, template literals, arrow functions, binary and octal literals, rest and spread, default parameters, etc. work together to make ES2015 code more terse, readable, and maintainable,” claimed Terlson, a sentiment to which Herman agreed.
Transpilers; tools and testing grounds
In fact, those transpilers have had ES2015 features for quite some time, and many of the new features have actually been prototyped in transpilers, so they’re already tried and tested.
“With transpilers, developers can try out new features in their real production apps even without native browser support, which means the standards get valuable experience reports, bug reports, and usability feedback before it’s too late to change. And developers don’t have to worry about their code silently breaking because they get to decide when they’re ready to upgrade to a new version of their transpiler.”
“The ECMAScript standards committee takes backward compatibility as an extremely serious responsibility,” Herman said. “ES2015 was carefully designed to cause no breaking changes to real-world code. The same goes for the browser vendors, agrees Terlson. “TC39 and engine implementers go to great lengths to ensure new language features do not introduce incompatibilities. Where the language has introduced incompatibilities in the past have been in edge case scenarios where we have data that no one or very few people are affected. In such cases, committee members or implementers will reach out to the affected libraries or sites to address the issue. Developers can sleep soundly knowing that TC39 is committed to not breaking their code.”
Feature image via Pixabay.