From d5044d0501d68f56820a606157acaf2b1f9d8a02 Mon Sep 17 00:00:00 2001 From: Henry <617822642@qq.com> Date: Tue, 9 Oct 2018 16:54:03 +0800 Subject: [PATCH] more semantic version --- snippets/throttle.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snippets/throttle.md b/snippets/throttle.md index 77bfacc52..3b9801d36 100644 --- a/snippets/throttle.md +++ b/snippets/throttle.md @@ -19,14 +19,12 @@ const throttle = (fn, wait) => { inThrottle = true; } else { clearTimeout(lastFn); - let time = 0; lastFn = setTimeout(function() { if (Date.now() - lastTime >= wait) { fn.apply(context, args); lastTime = Date.now(); } - time = wait - (Date.now() - lastTime) - }, time>0 ? time : 0); + }, Math.max(wait - (Date.now() - lastTime), 0)); } }; };