At this time many of the popular browsers support a subset of the new features present in the proposed standard. This is great for experimentation but can be seen as an issue if you wish to target your currently supported browser list. However, with the use of transpilers such as Traceur or Babel (formally 6to5), we can write code using the latest standards which in-turn gets automatically transformed into a representation compatible with ECMAScript 5 runtimes.
On a completely separate topic, as Sten’s previous article may have shown, the team is currently also very interested in Functional programming and the concepts that accompany it. I too find this paradigm very interesting to investigate, and through recent completion of a Front-end masters course on the subject I found a way to meld my desire to explore ES6 along with some of these functional concepts.
Partial Application and Currying
Reading the small example above you will first notice the use of the ‘var’ replacement ‘let’ keyword, which provides you with block-scoped binding and no implicit variable hoisting. The variadic functions definition uses the new arrow syntax along with the rest operator to collect any arguments that are supplied along with the function to eventually apply. Following this, a private recursive function is called, which in its base-case applies all the collected arguments to the specified function and returns the result. If this condition has not yet been met, a new function is instead returned with a call to the internal function, supplying it with the accumulated and new arguments using the spread operator. This example also takes advantage of the arrow functions behaviour to return the result if only one statement has been defined, removing the need for unnecessary ‘return’ keywords.
Another Functional building block is the ability to create new functionality by way of function composition. In a similar manner to how we implemented partial application, we are also able to use ES6’s new features to aid us in creating a composition function.