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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.