11 lines
334 B
TypeScript
11 lines
334 B
TypeScript
export function debounce(func: Function, delay = 300) {
|
|
let debounceTimer: ReturnType<typeof setTimeout>
|
|
return function () {
|
|
// @ts-expect-error this in TypeScript
|
|
const context = this
|
|
const args = arguments
|
|
clearTimeout(debounceTimer)
|
|
debounceTimer = setTimeout(() => func.apply(context, args), delay)
|
|
}
|
|
}
|