Function constraints

Similar to decorating functions with new behavior are the constraints imposed on functions. This impacts when and how often the function can be called. Function constraints also control how values returned by calling a function are cached. Lo-Dash has functions that deal with each of these scenarios.

Limiting call counts

There are two Lo-Dash functions that deal with counting the number of times a given function is called. The after() function will execute a callback after the composed function is called a given number of times. The once() function constrains the given function to being called only once. Let's look at after() and see how it works:

function work(value) { progress(); } function reportProgress() { console.log(++complete ...

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.