DEV/DEV4.1/tp3/ex1/js/helpers.js

13 lines
341 B
JavaScript
Raw Normal View History

2024-03-01 15:39:57 +01:00
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds.
function debounce(fn, wait) {
let timeout
return (...args) => {
clearTimeout(timeout)
timeout = setTimeout(() => fn(...args), wait)
}
}
export default debounce