O'Reilly logo

Mastering JavaScript Functional Programming by Federico Kereki

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chaining and fluent interfaces

When you work with objects or arrays, there is another way of linking the execution of several calls together, by applying chaining. For example, when you work with arrays, if you apply a .map() or .filter() method, the result is a new array, to which you can apply a new further method, and so forth. We have already used such methods, as when we defined the range() function back in the Working with ranges section of Chapter 5, Programming Declaratively - A Better Style:

const range = (start, stop) =>    new Array(stop - start).fill(0).map((v, i) => start + i);

First, we created a new array; then, we applied the .fill() method to it, which updated the array in place (side effect...) and returned the updated array, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required