debounce

mail@pastecode.io avatar
unknown
javascript
3 years ago
267 B
2
Indexable
Never
const debounce = (callback, delay = 1000) => {
    let timeoutId;

    return (...arg) => {
        if (timeoutId) {
            clearTimeout(timeoutId)
        }
        timeoutId = setTimeout(() => {
            callback.apply(null, arg);
        }, delay);
    }
}