Returning wrappers

Wrappers and the function call chains that follow don't exist randomly throughout our code. The next chapter covers this topic in more depth, so consider this as a teaser. So far, we've only looked at chains as they're constructed and executed in the same statement. However, if we're going through all the trouble of designing a call chain that serves a general purpose, wouldn't it be good not to keep assembling that chain? Let's design the chain with the following code:

function best(coll, prop, count) { return _(coll) .sortBy(prop) .takeRight(count); } var collection = [ { name: 'Mathew', score: 92 }, { name: 'Michele', score: 89 }, { name: 'Joe', score: 74 }, { name: 'Laurie', score: 83 } ]; var bestScore = best(collection, ...

Get Lo-Dash Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.