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

Improving performance


Just because Lo-Dash is designed from the ground up for optimal performance, it doesn't mean there are no basic modifications we can make to our Lo-Dash code to improve performance. In fact, we can sometimes borrow some Lo-Dash design principles and apply them directly to our code that utilizes Lo-Dash.

Changing the operation order

Using a Lo-Dash wrapper around a value, such as an array, lets us chain together many operations on that value. As we saw in Chapter 6, Application Building Blocks, a wrapper has many advantages over stitching together, piecemeal, several statements that call Lo-Dash functions. For example, the end result is often more concise and readable code. The different orders in which we call these operations in a chain can yield the same result and yet have different performance implications. Let's look at three different approaches to filtering a collection that get us the same result:

var collection = _.map(_.range(100), function(item) {
    return...