Skip to content

Instantly share code, notes, and snippets.

View jrrio's full-sized avatar

João Rodrigues jrrio

View GitHub Profile
@jrrio
jrrio / Debounce.js
Created August 25, 2024 21:22
Debounce is used to limit the number of times a function is called in a short period of time.
/**
* Debounce is used to limit the number of times a function is called in a short period of time.
* @param {Function} func
* @param {Number} wait - a delay in milliseconds, usually 250 ms by default.
* @returns {Function} a new function that will delay the execution of the original function.
*/
const debounce = (func, wait = 250) => {
let timeout;
return function (event) {
// console.log(`debounced ${func.name} called`)