mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Ensure _.debounce with leading and trailing will call the func on the leading edge after a trailing call is performed. [closes #257]
Former-commit-id: 97afe842b2b4c3eb20c9557298e01ec268386ea2
This commit is contained in:
@@ -4482,6 +4482,7 @@
|
||||
*/
|
||||
function debounce(func, wait, options) {
|
||||
var args,
|
||||
calledTwice,
|
||||
inited,
|
||||
result,
|
||||
thisArg,
|
||||
@@ -4489,8 +4490,9 @@
|
||||
trailing = true;
|
||||
|
||||
function delayed() {
|
||||
inited = timeoutId = null;
|
||||
if (trailing) {
|
||||
var callTrailing = trailing && ((leading && calledTwice) || !leading);
|
||||
calledTwice = inited = timeoutId = null;
|
||||
if (callTrailing) {
|
||||
result = func.apply(thisArg, args);
|
||||
}
|
||||
}
|
||||
@@ -4510,8 +4512,9 @@
|
||||
inited = true;
|
||||
result = func.apply(thisArg, args);
|
||||
} else {
|
||||
timeoutId = setTimeout(delayed, wait);
|
||||
calledTwice = true;
|
||||
}
|
||||
timeoutId = setTimeout(delayed, wait);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user