Try out JavaScript 6 features while you wait for the real thing

The 6to5 project transpiles ECMAScript 6 to ECMAScript 5 code

If you've been itching to take advantage of the wealth of features offered by ECMAScript 6, aka JavaScript 6, but you're tired of waiting for browsers and runtime engines to get fully caught up, there's a potential solution.

6to5 is a transpiler that transforms ECMAScript 6 code into completely backward-compatible ECMAScript 5 code, with support for ES6's most notable features, including arrow notation, classes, template strings, the "let" and "const" assignment, and constructs.

6to5 also preserves the readability of existing code so that the results are readable on their own terms and not the product of the UglifyJS minifier.

Much of 6to5's competition comes from other transpilers like Google's Traceur, but setting 6to5 apart, according to project lead Sebastian McKenzie, is the philosophy behind the project: minimal dependencies on polyfills or runtimes, readable output, and a high degree of compatibility with existing build systems and environments like Node.js.

Most of ES6's syntactical advances, like those mentioned above, are supported natively by 6to5. Support for inline Unicode literals and modules are available (with many common module formats like Common.js supported), but are disabled by default. Some features require a polyfill, an include that provides more complete emulation of an ES6 environment, but you can also elect to include only the needed components. However, a very small number of features, like proxies or tail calls, are not supported at all in 6to5.

According to McKenzie, 6to5 was inspired by his burgeoning curiosity in parsers and was created in part to help him understand the topic. "[6to5] was never intended to be this big project from the get-go," McKenzie admitted in an email conversation. "One of my friends who has a good following on GitHub actually starred it, and I woke up one day to a bunch of issues and hundreds of stars because some people started using it." Some of the people who've since come on board, he stated, include Ember core developer Stefan Penner.

One other possible point of comparison is with transpilers like CoffeeScript or TypeScript, which compile from a language of their design into JavaScript and can theoretically target any edition of JavaScript. But McKenzie feels his project is conceptually distinct from them.

"I think what separates [6to5] from projects like CoffeeScript is that they aren't working with a standard," McKenzie said. "You can't really be sure that it'll be developed as a language in the future, whereas with something like ES6 and JavaScript, you have the confidence that it's here to stay."

Support for many individual ES6 features is trickling into the various browsers. Firefox, for instance, appears to be adding them more aggressively than Chrome, and in Chrome's case an experimental-features flag must be enabled to take advantage of those functions. It isn't clear when full ES6 support is slated to arrive; in the meantime plenty of space for third parties, like 6to5, can help smooth the transition.

Copyright © 2015 IDG Communications, Inc.

How to choose a low-code development platform