From 24f49c8d83d3af097de392a78e3694614d0c6c2b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 11 Jun 2013 08:19:54 -0700 Subject: [PATCH] Ensure `_.throttle` passes underscore unit tests in all environments. Former-commit-id: 5867875313995ed02a94cd879d537c295b8a5c5f --- dist/lodash.compat.js | 38 +++++++++++++++++++++----------- dist/lodash.compat.min.js | 6 ++--- dist/lodash.js | 38 +++++++++++++++++++++----------- dist/lodash.min.js | 6 ++--- doc/README.md | 46 +++++++++++++++++++-------------------- lodash.js | 38 +++++++++++++++++++++----------- 6 files changed, 104 insertions(+), 68 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index ea4efaeb6..fc33644fa 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -4825,34 +4825,42 @@ timeoutId = null, trailing = true; - function trailingCall() { - var isCalled = trailing && (!leading || callCount > 1); - callCount = 0; - + function clear() { clearTimeout(maxTimeoutId); clearTimeout(timeoutId); + callCount = 0; maxTimeoutId = timeoutId = null; + } + function delayed() { + var isCalled = trailing && (!leading || callCount > 1); + clear(); if (isCalled) { + if (maxWait !== false) { + lastCalled = new Date; + } + result = func.apply(thisArg, args); + } + } + + function maxDelayed() { + clear(); + if (trailing || (maxWait !== wait)) { lastCalled = new Date; result = func.apply(thisArg, args); } } + wait = nativeMax(0, wait || 0); if (options === true) { var leading = true; trailing = false; } else if (isObject(options)) { - maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); leading = options.leading; + maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); trailing = 'trailing' in options ? options.trailing : trailing; } return function() { - var now = new Date; - if (!timeoutId && !leading) { - lastCalled = now; - } - var remaining = (maxWait || wait) - (now - lastCalled); args = arguments; thisArg = this; callCount++; @@ -4860,13 +4868,17 @@ // avoid issues with Titanium and `undefined` timeout ids // https://github.com/appcelerator/titanium_mobile/blob/3_1_0_GA/android/titanium/src/java/ti/modules/titanium/TitaniumModule.java#L185-L192 clearTimeout(timeoutId); - timeoutId = null; if (maxWait === false) { if (leading && callCount < 2) { result = func.apply(thisArg, args); } } else { + var now = new Date; + if (!maxTimeoutId && !leading) { + lastCalled = now; + } + var remaining = maxWait - (now - lastCalled); if (remaining <= 0) { clearTimeout(maxTimeoutId); maxTimeoutId = null; @@ -4874,11 +4886,11 @@ result = func.apply(thisArg, args); } else if (!maxTimeoutId) { - maxTimeoutId = setTimeout(trailingCall, remaining); + maxTimeoutId = setTimeout(maxDelayed, remaining); } } if (wait !== maxWait) { - timeoutId = setTimeout(trailingCall, wait); + timeoutId = setTimeout(delayed, wait); } return result; }; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index d7133dc72..e19b2ee23 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -21,9 +21,9 @@ return Tr(n,function(n,r,u){return t(n,r,u)?(e=n,b):void 0}),e}r=-1;for(var u=n. i>a&&(a=i)}}else t=!t&&dt(n)?u:_.createCallback(t,r),Tr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,a=n)});return a}function St(n,t,r,e){var u=3>arguments.length;if(t=_.createCallback(t,e,4),qr(n)){var a=-1,o=n.length;for(u&&(r=n[++a]);++aarguments.length;if(typeof a!="number")var i=Rr(n),a=i.length;else Pr.unindexedChars&&dt(n)&&(u=n.split(""));return t=_.createCallback(t,e,4),xt(n,function(n,e,l){e=i?i[--a]:--a,r=o?(o=b,u[e]):t(r,u[e],e,l) }),r}function It(n,t,r){var e;if(t=_.createCallback(t,r),qr(n)){r=-1;for(var u=n.length;++r=O&&u===t;if(c){var f=o(i);f?(u=r,i=f):c=b}for(;++eu(i,f)&&l.push(f);return c&&g(i),l}function Nt(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&t!=d){var a=-1;for(t=_.createCallback(t,r);++ae?kr(0,u+e):e||0}else if(e)return e=Ft(n,r),n[e]===r?e:-1;return n?t(n,r,e):-1}function zt(n,t,r){if(typeof t!="number"&&t!=d){var e=0,u=-1,a=n?n.length:0;for(t=_.createCallback(t,r);++u>>1,r(n[e])r?0:r);++ti&&(a=n.apply(o,u)):0c&&(i=n.apply(l,o));else{var r=new Kt;!s&&!h&&(f=r);var e=p-(r-f);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:z,variable:"",imports:{_:_}};var zr={a:"x,F,k",h:"var a=arguments,b=0,c=typeof k=='number'?2:a.length;while(++b 1); - callCount = 0; - + function clear() { clearTimeout(maxTimeoutId); clearTimeout(timeoutId); + callCount = 0; maxTimeoutId = timeoutId = null; + } + function delayed() { + var isCalled = trailing && (!leading || callCount > 1); + clear(); if (isCalled) { + if (maxWait !== false) { + lastCalled = new Date; + } + result = func.apply(thisArg, args); + } + } + + function maxDelayed() { + clear(); + if (trailing || (maxWait !== wait)) { lastCalled = new Date; result = func.apply(thisArg, args); } } + wait = nativeMax(0, wait || 0); if (options === true) { var leading = true; trailing = false; } else if (isObject(options)) { - maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); leading = options.leading; + maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); trailing = 'trailing' in options ? options.trailing : trailing; } return function() { - var now = new Date; - if (!timeoutId && !leading) { - lastCalled = now; - } - var remaining = (maxWait || wait) - (now - lastCalled); args = arguments; thisArg = this; callCount++; @@ -4525,13 +4533,17 @@ // avoid issues with Titanium and `undefined` timeout ids // https://github.com/appcelerator/titanium_mobile/blob/3_1_0_GA/android/titanium/src/java/ti/modules/titanium/TitaniumModule.java#L185-L192 clearTimeout(timeoutId); - timeoutId = null; if (maxWait === false) { if (leading && callCount < 2) { result = func.apply(thisArg, args); } } else { + var now = new Date; + if (!maxTimeoutId && !leading) { + lastCalled = now; + } + var remaining = maxWait - (now - lastCalled); if (remaining <= 0) { clearTimeout(maxTimeoutId); maxTimeoutId = null; @@ -4539,11 +4551,11 @@ result = func.apply(thisArg, args); } else if (!maxTimeoutId) { - maxTimeoutId = setTimeout(trailingCall, remaining); + maxTimeoutId = setTimeout(maxDelayed, remaining); } } if (wait !== maxWait) { - timeoutId = setTimeout(trailingCall, wait); + timeoutId = setTimeout(delayed, wait); } return result; }; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 5183ed639..0e60dee41 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -21,9 +21,9 @@ if(t&&((u=Ee(t))||m(t))){for(a=i.length;a--;)if(r=i[a]==t){f=l[a];break}if(!r){v }}else t=!t&&yt(n)?u:tt.createCallback(t,e),wt(n,function(n,e,u){e=t(n,e,u),e>r&&(r=e,a=n)});return a}function Ot(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Mt(r);++earguments.length;t=tt.createCallback(t,r,4);var a=-1,o=n.length;if(typeof o=="number")for(u&&(e=n[++a]);++aarguments.length; if(typeof u!="number")var o=Se(n),u=o.length;return t=tt.createCallback(t,r,4),wt(n,function(r,i,f){i=o?o[--u]:--u,e=a?(a=b,n[i]):t(e,n[i],i,f)}),e}function It(n,t,e){var r;t=tt.createCallback(t,e),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++e=w&&u===t;if(l){var c=o(i);c?(u=e,i=c):l=b}for(;++ru(i,c)&&f.push(c); return l&&p(i),f}function Nt(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=y){var a=-1;for(t=tt.createCallback(t,e);++ar?_e(0,u+r):r||0}else if(r)return r=Ft(n,e),n[r]===e?r:-1;return n?t(n,e,r):-1}function Bt(n,t,e){if(typeof t!="number"&&t!=y){var r=0,u=-1,a=n?n.length:0;for(t=tt.createCallback(t,e);++u>>1,e(n[r])e?0:e);++ti&&(a=n.apply(o,u)):0>>1,e(n[r])e?0:e);++tl&&(i=n.apply(f,o));else{var e=new Vt;!s&&!m&&(c=e);var r=p-(e-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:tt}};var Ee=ye,Se=de?function(n){return gt(n)?de(n):[]}:Z,Ie={"&":"&","<":"<",">":">",'"':""","'":"'"},Ae=pt(Ie),Ut=ot(function $e(n,t,e){for(var r=-1,u=n?n.length:0,a=[];++r=w&&i===t,g=u||v?f():s;if(v){var h=o(g);h?(i=e,g=h):(v=b,g=u?g:(c(g),s))}for(;++ai(g,y))&&((u||v)&&g.push(y),s.push(h))}return v?(c(g.b),p(g)):u&&c(g),s});return Ht&&Y&&typeof pe=="function"&&(zt=qt(pe,r)),pe=8==je(B+"08")?je:function(n,t){return je(yt(n)?n.replace(F,""):n,t||0)},tt.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0 }},tt.assign=X,tt.at=function(n){for(var t=-1,e=ae.apply(Zt,Ce.call(arguments,1)),r=e.length,u=Mt(r);++t ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5614 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5626 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -1009,7 +1009,7 @@ _([1, 2, 3, 4]) ### `_.prototype.toString()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5631 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5643 "View in source") [Ⓣ][1] Produces the `toString` result of the wrapped value. @@ -1030,7 +1030,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.valueOf()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5648 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5660 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2116,7 +2116,7 @@ jQuery('#postbox').on('click', _.debounce(sendMail, 200, { ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4921 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4933 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -2141,7 +2141,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4947 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4959 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -2168,7 +2168,7 @@ _.delay(log, 1000, 'logged later'); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4972 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4984 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. The `func` is executed with the `this` binding of the memoized function. The result cache is exposed as the `cache` property on the memoized function. @@ -2194,7 +2194,7 @@ var fibonacci = _.memoize(function(n) { ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5002 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5014 "View in source") [Ⓣ][1] Creates a function that is restricted to execute `func` once. Repeat calls to the function will return the value of the first call. The `func` is executed with the `this` binding of the created function. @@ -2220,7 +2220,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5037 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5049 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `_.bind`, except it does **not** alter the `this` binding. @@ -2247,7 +2247,7 @@ hi('moe'); ### `_.partialRight(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5068 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5080 "View in source") [Ⓣ][1] This method is similar to `_.partial`, except that `partial` arguments are appended to those passed to the new function. @@ -2284,7 +2284,7 @@ options.imports ### `_.throttle(func, wait, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5101 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5113 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. Pass an `options` object to indicate that `func` should be invoked on the leading and/or trailing edge of the `wait` timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2316,7 +2316,7 @@ jQuery('.interactive').on('click', _.throttle(renewToken, 300000, { ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5142 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5154 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the function are appended to those passed to the `wrapper` function. The `wrapper` is executed with the `this` binding of the created function. @@ -3397,7 +3397,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5166 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5178 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -3421,7 +3421,7 @@ _.escape('Moe, Larry & Curly'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5184 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5196 "View in source") [Ⓣ][1] This method returns the first argument passed to it. @@ -3446,7 +3446,7 @@ moe === _.identity(moe); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5210 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5222 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -3476,7 +3476,7 @@ _('moe').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5239 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5251 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -3496,7 +3496,7 @@ var lodash = _.noConflict(); ### `_.parseInt(value [, radix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5263 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5275 "View in source") [Ⓣ][1] Converts the given `value` into an integer of the specified `radix`. If `radix` is `undefined` or `0`, a `radix` of `10` is used unless the `value` is a hexadecimal, in which case a `radix` of `16` is used. @@ -3523,7 +3523,7 @@ _.parseInt('08'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5286 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5298 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -3551,7 +3551,7 @@ _.random(5); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5330 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5342 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function, it will be invoked with the `this` binding of `object` and its result returned, else the property value is returned. If `object` is falsey, then `undefined` is returned. @@ -3604,7 +3604,7 @@ Create a new `lodash` function using the given `context` object. ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5414 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5426 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -3686,7 +3686,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5539 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5551 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -3718,7 +3718,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5566 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5578 "View in source") [Ⓣ][1] The inverse of `_.escape`, this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -3742,7 +3742,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5586 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5598 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is passed, the ID will be appended to it. @@ -3795,7 +3795,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5829 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5841 "View in source") [Ⓣ][1] *(String)*: The semantic version number. diff --git a/lodash.js b/lodash.js index e84a60674..ac0ea5358 100644 --- a/lodash.js +++ b/lodash.js @@ -4844,34 +4844,42 @@ timeoutId = null, trailing = true; - function trailingCall() { - var isCalled = trailing && (!leading || callCount > 1); - callCount = 0; - + function clear() { clearTimeout(maxTimeoutId); clearTimeout(timeoutId); + callCount = 0; maxTimeoutId = timeoutId = null; + } + function delayed() { + var isCalled = trailing && (!leading || callCount > 1); + clear(); if (isCalled) { + if (maxWait !== false) { + lastCalled = new Date; + } + result = func.apply(thisArg, args); + } + } + + function maxDelayed() { + clear(); + if (trailing || (maxWait !== wait)) { lastCalled = new Date; result = func.apply(thisArg, args); } } + wait = nativeMax(0, wait || 0); if (options === true) { var leading = true; trailing = false; } else if (isObject(options)) { - maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); leading = options.leading; + maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); trailing = 'trailing' in options ? options.trailing : trailing; } return function() { - var now = new Date; - if (!timeoutId && !leading) { - lastCalled = now; - } - var remaining = (maxWait || wait) - (now - lastCalled); args = arguments; thisArg = this; callCount++; @@ -4879,13 +4887,17 @@ // avoid issues with Titanium and `undefined` timeout ids // https://github.com/appcelerator/titanium_mobile/blob/3_1_0_GA/android/titanium/src/java/ti/modules/titanium/TitaniumModule.java#L185-L192 clearTimeout(timeoutId); - timeoutId = null; if (maxWait === false) { if (leading && callCount < 2) { result = func.apply(thisArg, args); } } else { + var now = new Date; + if (!maxTimeoutId && !leading) { + lastCalled = now; + } + var remaining = maxWait - (now - lastCalled); if (remaining <= 0) { clearTimeout(maxTimeoutId); maxTimeoutId = null; @@ -4893,11 +4905,11 @@ result = func.apply(thisArg, args); } else if (!maxTimeoutId) { - maxTimeoutId = setTimeout(trailingCall, remaining); + maxTimeoutId = setTimeout(maxDelayed, remaining); } } if (wait !== maxWait) { - timeoutId = setTimeout(trailingCall, wait); + timeoutId = setTimeout(delayed, wait); } return result; };