types: 'this' issue in debounce function

This commit is contained in:
TaroSunn
2023-06-12 20:38:23 +08:00
committed by GitHub
parent b92bd407dd
commit 0a0ab44058
2 changed files with 2 additions and 4 deletions
+1 -2
View File
@@ -1,11 +1,10 @@
export function debounce(func: Function, delay: number) {
let timer: number
return function (...args: any) {
return function (this: any, ...args: any[]) {
if (timer) {
window.clearTimeout(timer)
}
timer = window.setTimeout(() => {
// @ts-ignore
func.apply(this, args)
}, delay)
}