Arrow Function Semantics

In the last post, we took a deep-dive into the syntax of JavaScript’s new arrow functions. It’s great to see a new language feature that’s able to remove so much boilerplate from an idiomatic ES5 example.

But arrow functions are much more than function expressions with a fresh coat of paint. On top of the new appearance, there are some significant differences in the way they behave too.

This post explores these new behaviours; including why arrow functions don’t have their own values for this or arguments, and what that means for the code you write.


Arrow Function Syntax

The next version of JavaScript - called ES2015 (née ES6) - has just shipped. It’s final, so there won’t be any semantic or syntactic changes. What there will be are plenty of great features that coming to a JavaScript engine near you. Soon.

Even for engines that don’t implement ES2015 yet, you can use Babel to compile lots of those features into valid ES5 (the previous generation of JavaScript). This lets you run code levering the new goodness in all modern browsers, Node.js and most other places where JavaScript is used.

I’m a programmer who uses functions like a preschooler uses glitter, so arrow functions is one of the features I’m really excited about. Here’s what I’ve learnt from reading the specification, reading forum discussions and testing things out in the Babel playground.


Why Curry Helps

A programmer’s pipe-dream is to write code, and be able to use it repeatedly with little effort. It’s expressive because you write in a way that expresses what is needed, and it’s reuse because.. well, you’re reusing. What more could you want?

curry can help.


Vars And Values

Sometimes I hear JavaScript dev throw around the terms vars and values as synonyms for each other. Realising that they’re not was a serious ‘aha’ moment for me - and making the distinction about it can make talking and thinking about code clearer by far.


Tapping Into The Method Chain

Objects and methods are a big deal. They’re the core way in which JavaScript defines functionality against a type; which is reflected in the standard library, in many of the libraries we choose to use, and how production code tends to be written (at least, in my experience).

Compare these two solutions for returning the name of all the audiophiles in a contact book:


Jslint Is Not A Code Quality Tool For 3rd Party Code

Doug Crockford’s JSLint performs static analysis on Javascript, returning a list of what Crockford considers to be violations of best practice. Contrary to the assertions of its creator, however, it is not a fit tool by which to judge the quality of 3rd party code.


Prototypes: The Short(est Possible) Story

Prototypal inheritance is a brilliantly simple concept. Javascript’s syntax, however, often confuses new-comers. Let’s solve that, ehy?