One drawback of living on the cutting edge is it can be lonely. Web developers realized this long ago with different browsers supporting different aspects of web standards, which have led to so many workarounds.
Living in Harmony
This version adds a lot of language features that seemingly move it in the direction of full-featured languages like Java. The ECMAScript team posted goals online that give you an idea of what they wanted to accomplish with the new version — one of the main goals (and first on the list) was a better language to write complex applications. This is a list of my favorite new features.
- There are new ways to work with variables like use the Let statement in place of var, along with defining constants with const.
- Iterators have been added to make it easier to work with collections of data. One example is the addition of the for/of loop, which makes it easy to access each value of a collection. New collection types (map and sets) have been added to the familiar objects and arrays.
- Arrow functions allow functions to be defined using arrows (like =>), which can save typing and lead to cleaner code. Also, arrow functions can be used for Immediately-Invoked Function Expressions.
- There are a number of array enhancements, including powerful comprehensions for creating new arrays via existing arrays and user-defined criteria. Also, the spread operator allows you to explode an array into its individual elements.
- Generators are a unique feature that allow you to create routines with suspended execution contexts — you yield values until no more exist. While I am not a Python programmer, I have been told this mimics a Python feature.
The specifics of the new features are beyond this article but, with so many features and so many target platforms, it makes it hard to imagine industry conformity. After all, many of us are well versed in dealing with the inconsistent CSS and HTML standards across different browsers (yes, I'm looking at you Internet Explorer).
Tomorrow is here, thanks to transpilers
There are some of the popular transpilers that are available:
- 6to5: This is the most comprehensive option, as it supports the most ECMAScript 6 features at this time. It is widely supported and used with great documentation and support for the more popular environments/tools such as Node, Ruby, and Grunt.
The new features and changes in ECMAScript 6 are exciting, though they do present a learning curve. Figure A provides a demo of how much leaner the code can be, with version 6 code on the left and its version 5 equivalent on the right.
6to5 offers an online playground for working with code.
Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a production environment on a daily basis.