From 34c7c04d7366c8ef6c1a2feda3f29448c618340e Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 20 Apr 2022 11:34:54 +0800 Subject: [PATCH] fix: Can only call Window.clearTimeout on instances of Window --- packages/uni-shared/src/debounce.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/uni-shared/src/debounce.ts b/packages/uni-shared/src/debounce.ts index b42b37743..57c4425e2 100644 --- a/packages/uni-shared/src/debounce.ts +++ b/packages/uni-shared/src/debounce.ts @@ -9,15 +9,19 @@ interface Timer { * @param timer * @returns */ -export function debounce(fn: Function, delay: number, timer: Timer) { +export function debounce( + fn: Function, + delay: number, + { clearTimeout, setTimeout }: Timer +) { let timeout: any const newFn = function (this: any) { - timer.clearTimeout(timeout) + clearTimeout(timeout) const timerFn = () => fn.apply(this, arguments) - timeout = timer.setTimeout(timerFn, delay) + timeout = setTimeout(timerFn, delay) } newFn.cancel = function () { - timer.clearTimeout(timeout) + clearTimeout(timeout) } return newFn } -- GitLab