-
Book Overview & Buying
-
Table Of Contents
Lo-Dash Essentials
By :
With the introduction of Lo-Dash 3.0, some functions use a lazy evaluation to compute their results. This simply means that the items in a given collection aren't iterated over until they're actually needed. It's figuring out when they're needed that is the tricky part. For example, just calling a single Lo-Dash function doesn't invoke any lazy evaluation mechanism. However, operations that are chained together could certainly benefit from this approach, in certain circumstances. For example, when we're only taking 10 items from the result, there's no need to iterate over the entire collection further up the chain.
To get an idea of what a lazy evaluation looks like, let's write some code to utilize it. There's nothing explicit to be done. The lazy mechanism happens transparently, behind the scenes, depending on which operations make up our chain and what order they're called in:
var collection = _.range(10);
_(collection)
.reject(function(item) {
console.log(...
Change the font size
Change margin width
Change background colour