Lodash debounce reference
11 January 2023 (Updated 14 January 2023)
On this page
In a nutshell
This is the method signature:
_.debounce(func, [wait=0], [options={}])
Lodash’s debounce function creates a “debounced” function that delays invoking the given func until after wait milliseconds have elapsed since the last invocation.
Examples
// Avoid costly calculations while the window size is in flux.
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// Cancel the trailing debounced invocation.
jQuery(window).on('popstate', debounced.cancel);
Other notes
- You can use a
cancelmethod to cancel delayedfuncinvocations. - You can use a
flushmethod to immediately invoke delayedfuncinvocations. - The
funcwill be invoked with the last arguments passed to debounced function. - Subsequent calls of
funcwill return the result of the last invocation.
Sources
Tagged:
JavaScript tooling
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment