Skip to content

Instantly share code, notes, and snippets.

@ZatsuneNoMokou
ZatsuneNoMokou / debounce.js
Last active January 19, 2025 11:31 — forked from beshur/debounce.js
javascript debounce
/**
* Debounce creates a FUNCTION that when invoked, delays invoking fn for wait milliseconds since
* the last time it is called.
*
* @see https://gist.github.com/ZatsuneNoMokou/6d0af1783c348facde59c92c53a63b1f/617ccd3e858446983aa166b322ccb30319cf6dd8
* @param {number} fn - function to call
* @param {number} wait - duration in milliseconds
* @param {number} maxWait - max duration in milliseconds before calling {@param fn}
* @retun {function} a function that will wait {@param wait} milliseconds since it's last called to invoke {@param fn}.
*/