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

Decorating functions


A decorator does what the name implies. It decorates functions with additional capabilities. It's like an adornment for a piece of functionality. For example, let's say we've already implemented a function that looks up data in some structure. It's already used throughout our application, but now we're implementing a new component that requires this same functionality and something extra. We can use the function-decorating tools provided by Lo-Dash to take existing functions and extend them.

There are two flavors of Lo-Dash function decoration: Partials, which construct new functions that have the arguments of the original function partially supplied, and Wrappers, which build a new function that wraps the original function with a whole new function.

Partials

To create a partial function using Lo-Dash, you use the partial() function. The resulting function then has some arguments presupplied—we don't have to supply them again when called. This concept is really useful...