mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Ensure wait of _.debounce and _.throttle defaults to 0. [closes #991]
This commit is contained in:
@@ -7376,7 +7376,7 @@
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to debounce.
|
||||
* @param {number} wait The number of milliseconds to delay.
|
||||
* @param {number} [wait=0] The number of milliseconds to delay.
|
||||
* @param {Object} [options] The options object.
|
||||
* @param {boolean} [options.leading=false] Specify invoking on the leading
|
||||
* edge of the timeout.
|
||||
@@ -7434,7 +7434,7 @@
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
wait = wait < 0 ? 0 : wait;
|
||||
wait = wait < 0 ? 0 : (+wait || 0);
|
||||
if (options === true) {
|
||||
var leading = true;
|
||||
trailing = false;
|
||||
@@ -7955,7 +7955,7 @@
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to throttle.
|
||||
* @param {number} wait The number of milliseconds to throttle invocations to.
|
||||
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
||||
* @param {Object} [options] The options object.
|
||||
* @param {boolean} [options.leading=true] Specify invoking on the leading
|
||||
* edge of the timeout.
|
||||
|
||||
22
test/test.js
22
test/test.js
@@ -13889,6 +13889,28 @@
|
||||
ok(pass);
|
||||
});
|
||||
|
||||
asyncTest('_.' + methodName + ' should have a default `wait` of `0`', 1, function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var callCount = 0;
|
||||
|
||||
var funced = func(function() {
|
||||
callCount++;
|
||||
});
|
||||
|
||||
funced();
|
||||
|
||||
setTimeout(function() {
|
||||
funced();
|
||||
strictEqual(callCount, isDebounce ? 1 : 2);
|
||||
QUnit.start();
|
||||
}, 32);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('_.' + methodName + ' should call `func` with the correct `this` binding', 1, function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var object = {
|
||||
|
||||
Reference in New Issue
Block a user