For the More Curious: Arrow Functions

We fibbed. Arrow functions do not work exactly like anonymous functions. For some situations, they are better.

In addition to providing shorter syntax, arrow functions:

  • work as though you had written function () {}.bind(this), making this work as expected in the body of the arrow function

  • allow you to omit the curly braces if you only have one statement

  • return the result of the single statement when curly braces are omitted

For example, here is CoffeeRun’s CheckList.prototype.addClickHandler method:

CheckList.prototype.addClickHandler = function(fn) { this.$element.on('click', 'input', function (event) { var email = event.target.value; fn(email) .then( function () { this.removeRow(email); ...

Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.