Debouce
function test () { console.log('Hello World') }
const t = debounce(test, 500)
t()
t()
function debounce(fn, delay) {
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(()=> {
fn(args)
}, delay)
}
}
function test () { console.log('Hello World') }
const t = debounce(test, 500)
t()
t()
function debounce(fn, delay) {
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(()=> {
fn(args)
}, delay)
}
}