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 mixins


The last major building block we'll visit in this chapter is the mixin. Lo-Dash has a mixin() function that lets us extend the API by providing our own functions. There are two reasons you'd want to do such a thing. The first is that by placing your generic toolset in the Lo-Dash object, you can have access to them wherever the _ symbol is accessible. The second reason is that once you've mixed in your own function, it can be used as a piece in a function call chain.

Creating an average() function

There's only so many utilities a library such as Lo-Dash can feasibly ship. The ones that are viewed as most applicable to common users are the ones we get out of the box. This doesn't mean that the application you're working on doesn't have a high-value use case you wish Lo-Dash implemented. For example, assume your application computes averages all over the place. While the library doesn't ship with an average function, that doesn't mean we can't add this function to the code:

_...