Function Utilities in Lodash
Lodash provides several utility functions for working with functions. Here are some commonly used function methods:
Creates a debounced function that delays invoking func
until after wait
milliseconds have elapsed since the last time the debounced function was invoked.
// Avoid costly calculations while the window size is in flux.
JQuery(window).on('resize', _.debounce(calculateLayout, 150));
Creates a throttled function that only invokes func
at most once per every wait
milliseconds.
// Avoid excessively updating the position while scrolling.
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
Creates a function that memoizes the result of func
.
const object = { 'a': 1, 'b': 2 };
const other = { 'c': 3, 'd': 4 };
const values = _.memoize(_.values);
values(object);
// => [1, 2]
values(other);
// => [3, 4]
Previous: Object Methods Next: String Methods
Last updated 4 days ago