Book Image

Lo-Dash Essentials

By : Adam Boduch
Book Image

Lo-Dash Essentials

By: Adam Boduch

Overview of this book

Table of Contents (15 chapters)
Lo-Dash Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating Lo-Dash wrappers


In this section, we'll introduce the concept of wrapping values. Then we'll use the wrapper to chain function calls. We'll also look at how call chains are terminated.

Chained calls

Chaining function calls together is a pattern of applicative programming, where a collection is transformed into something different. This newly transformed collection is then passed to the next call in the chain, and so on. This is where the term applicative comes from; you're applying functions to every item in a collection. Since this process is repeated over and over, it's easy to package chained calls into a reusable component. It's a pipeline that's adding, removing, or modifying values along each step of the way, producing a result at the end.

Another way, perhaps, is a more practical view of chains, which is just a simpler way to make function calls. jQuery popularized this notion. When reading jQuery code, you'll find that there are a lot of chained calls, and yet the code is readable...