Fix failing _.debounce test.

This commit is contained in:
John-David Dalton
2013-11-05 21:14:29 -08:00
parent 3e0c565019
commit eaaddf40d2

View File

@@ -5728,14 +5728,15 @@
if (!maxTimeoutId && !leading) { if (!maxTimeoutId && !leading) {
lastCalled = stamp; lastCalled = stamp;
} }
var remaining = maxWait - (stamp - lastCalled); var remaining = maxWait - (stamp - lastCalled),
if (remaining <= 0) { isCalled = remaining <= 0;
if (isCalled) {
if (maxTimeoutId) { if (maxTimeoutId) {
maxTimeoutId = clearTimeout(maxTimeoutId); maxTimeoutId = clearTimeout(maxTimeoutId);
} }
lastCalled = stamp; lastCalled = stamp;
result = func.apply(thisArg, args); result = func.apply(thisArg, args);
args = thisArg = null;
} }
else if (!maxTimeoutId) { else if (!maxTimeoutId) {
maxTimeoutId = setTimeout(maxDelayed, remaining); maxTimeoutId = setTimeout(maxDelayed, remaining);
@@ -5745,7 +5746,10 @@
timeoutId = setTimeout(delayed, wait); timeoutId = setTimeout(delayed, wait);
} }
if (leadingCall) { if (leadingCall) {
isCalled = true;
result = func.apply(thisArg, args); result = func.apply(thisArg, args);
}
if (isCalled && !timeoutId && !maxTimeoutId) {
args = thisArg = null; args = thisArg = null;
} }
return result; return result;