-
Book Overview & Buying
-
Table Of Contents
Lo-Dash Essentials
By :
With generic functions under our belts, it's time to turn our attention to Lo-Dash wrapper instances and create generic function call chains. Chains are useful when you're stuck and you need a quick way out of a tricky programming situation, but they're also useful in the generic sense. That is, you can compose chains of functionality that are general enough to apply in a variety of contexts.
Let's start by taking a look at generic filters and how they can be utilized in our functions. Filters are especially suitable for chained function calls since they can be stitched together by applying a filter after a preceding filter. There are often some kinds of sorting or other constraints that take place at the end of a filter, such as limiting the number of results returned, as shown in the following code:
function byName(coll, name, take) {
return _(coll)
.filter({ name: name })
.take(_.isUndefined(take) ? 100 : take)
.value...
Change the font size
Change margin width
Change background colour