From fe7da419562108b1da4226cf9107f63d697996b1 Mon Sep 17 00:00:00 2001 From: moonformeli Date: Tue, 12 Feb 2019 15:50:11 +0900 Subject: [PATCH] Cancel old timer, editing pr #4139 (#4187) * Cancel old timer, editing pr for $4139 --- debounce.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debounce.js b/debounce.js index 581a4c259..e48e8ffaa 100644 --- a/debounce.js +++ b/debounce.js @@ -78,7 +78,7 @@ function debounce(func, wait, options) { // Bypass `requestAnimationFrame` by explicitly setting `wait=0`. const useRAF = (!wait && wait !== 0 && typeof root.requestAnimationFrame === 'function') - if (typeof func != 'function') { + if (typeof func !== 'function') { throw new TypeError('Expected a function') } wait = +wait || 0 @@ -101,6 +101,7 @@ function debounce(func, wait, options) { function startTimer(pendingFunc, wait) { if (useRAF) { + root.cancelAnimationFrame(timerId); return root.requestAnimationFrame(pendingFunc) } return setTimeout(pendingFunc, wait)