-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Labels
Description
lodash.src.js (as of commit 5613f60) has this at line 7437 (the beginning steps of _.debounce):
wait = wait < 0 ? 0 : wait;
If you call debounce without a wait argument, i.e. _.debounce(f), the variable wait remains undefined. A bit later (starting at line 7457) there is this:
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
// cleanup and call debounced function
} else {
timeoutId = setTimeout(delayed, remaining);
}
}
Now, because wait is undefined, the value of remaining becomes NaN, and the test right below it is always false. Thus the delayed function is set as a timeout again, which is does the same thing again, etc. Basically it loops indefinitely.
I propose changing line 7457 to
wait = wait >= 0 ? +wait : 0;
which forces wait to be zero if it is undefined.