From eaaddf40d287bc67b41d2766cb017f354be94344 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 5 Nov 2013 21:14:29 -0800 Subject: [PATCH] Fix failing `_.debounce` test. --- lodash.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lodash.js b/lodash.js index 2b2f62348..0f44b8df7 100644 --- a/lodash.js +++ b/lodash.js @@ -5728,14 +5728,15 @@ if (!maxTimeoutId && !leading) { lastCalled = stamp; } - var remaining = maxWait - (stamp - lastCalled); - if (remaining <= 0) { + var remaining = maxWait - (stamp - lastCalled), + isCalled = remaining <= 0; + + if (isCalled) { if (maxTimeoutId) { maxTimeoutId = clearTimeout(maxTimeoutId); } lastCalled = stamp; result = func.apply(thisArg, args); - args = thisArg = null; } else if (!maxTimeoutId) { maxTimeoutId = setTimeout(maxDelayed, remaining); @@ -5745,7 +5746,10 @@ timeoutId = setTimeout(delayed, wait); } if (leadingCall) { + isCalled = true; result = func.apply(thisArg, args); + } + if (isCalled && !timeoutId && !maxTimeoutId) { args = thisArg = null; } return result;