函数防抖 - typescript

export function debounce(fn: any, t: number) {
let timeId: NodeJS.Timeout | null = null
const delay = t || 1000
return function (this: any, ...args: any) {
if(timeId) clearTimeout(timeId)
timeId = setTimeout(() => {
timeId = null
fn.apply(this, args)
}, delay)
}
}

posted @ 2021-03-30 15:05  狗子你终于回来了  阅读(370)  评论(0)    收藏  举报