From 1bb7c31ee4dce05e952ddf25dd5045c359d9f311 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 5 Nov 2013 21:41:13 -0800 Subject: [PATCH] Clear `timeoutId` if `func` is called in `_.debounce`. --- lodash.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 0f44b8df7..c381a10f2 100644 --- a/lodash.js +++ b/lodash.js @@ -5737,21 +5737,22 @@ } lastCalled = stamp; result = func.apply(thisArg, args); + args = thisArg = null; } else if (!maxTimeoutId) { maxTimeoutId = setTimeout(maxDelayed, remaining); } } - if (!timeoutId && wait !== maxWait) { + if (isCalled & timeoutId) { + timeoutId = clearTimeout(timeoutId); + } + else if (!timeoutId && wait !== maxWait) { timeoutId = setTimeout(delayed, wait); } if (leadingCall) { isCalled = true; result = func.apply(thisArg, args); } - if (isCalled && !timeoutId && !maxTimeoutId) { - args = thisArg = null; - } return result; }; }