types: 'this' issue in debounce function

pr675
TaroSunn 3 years ago committed by GitHub
parent b92bd407dd
commit 0a0ab44058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)
}

@ -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)
}

Loading…
Cancel
Save