From 277557cd995987178e60f6aa91c722edaf84b765 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 24 Aug 2013 23:32:04 -0700 Subject: [PATCH] Fix perf regressions in `_.bind`, `_.groupBy`, `_.countBy`, `_.indexBy`, and `_.reduceRight`. Former-commit-id: 0972dd65af64b7cd1d7f2800a8a59c28183b8aba --- build.js | 41 +++++++---- dist/lodash.compat.js | 132 +++++++++++++++++++++------------- dist/lodash.compat.min.js | 22 +++--- dist/lodash.js | 130 +++++++++++++++++++-------------- dist/lodash.min.js | 88 +++++++++++------------ dist/lodash.underscore.js | 122 +++++++++++++++++++------------ dist/lodash.underscore.min.js | 55 +++++++------- lodash.js | 98 +++++++++++++++---------- 8 files changed, 409 insertions(+), 279 deletions(-) diff --git a/build.js b/build.js index 36c7584a2..d449c96e1 100644 --- a/build.js +++ b/build.js @@ -112,7 +112,7 @@ 'assign': ['createIterator'], 'at': ['baseFlatten', 'isString'], 'bind': ['createBound'], - 'bindAll': ['baseFlatten', 'bind', 'functions'], + 'bindAll': ['baseFlatten', 'createBound', 'functions'], 'bindKey': ['createBound'], 'chain': ['lodashWrapper'], 'clone': ['baseClone', 'baseCreateCallback'], @@ -140,7 +140,7 @@ 'first': ['createCallback', 'slice'], 'flatten': ['baseFlatten', 'map'], 'forEach': ['baseCreateCallback', 'baseEach', 'isArray'], - 'forEachRight': ['baseCreateCallback', 'forEach', 'isString', 'keys'], + 'forEachRight': ['baseCreateCallback', 'baseEach', 'isArray', 'isString', 'keys'], 'forIn': ['createIterator'], 'forInRight': ['baseCreateCallback', 'forIn'], 'forOwn': ['createIterator'], @@ -240,7 +240,7 @@ 'cachePush': [], 'charAtCallback': [], 'compareAscending': [], - 'createAggregator': ['createCallback', 'forEach'], + 'createAggregator': ['baseEach', 'createCallback', 'isArray'], 'createBound': ['createObject', 'isFunction', 'isObject', 'setBindData'], 'createCache': ['cachePush', 'getObject', 'releaseObject'], 'createIterator': ['baseCreateCallback', 'getObject', 'isArguments', 'isArray', 'isString', 'iteratorTemplate', 'releaseObject'], @@ -1791,7 +1791,6 @@ source = source.replace(matchFunction(source, 'createBound'), function(match) { return match .replace(/(?:\s*\/\/.*)*\n( *)var bindData *=[\s\S]+?\n\1}/, '') - .replace(/(?:\s*\/\/.*)*\n.+bindData *= *nativeSlice.+/, '') .replace(/(?:\s*\/\/.*)*\n.+?setBindData.+/, ''); }); @@ -2320,11 +2319,6 @@ return match.replace(/^ *if *\(support\.unindexedChars[^}]+}\n+/m, ''); }); - // remove `support.unindexedChars` from `_.forEachRight` - source = source.replace(matchFunction(source, 'forEachRight'), function(match) { - return match.replace(/}\s*else if *\(support\.unindexedChars[^}]+/, ''); - }); - // remove `support.unindexedChars` from `_.toArray` source = source.replace(matchFunction(source, 'toArray'), function(match) { return match.replace(/(return\b).+?support\.unindexedChars[^:]+:\s*/, '$1 '); @@ -3067,7 +3061,7 @@ _.pull(funcDepMap[funcName], 'baseEach').push('forEach'); }); - _.each(['contains', 'every', 'filter', 'find', 'forEach', 'map', 'max', 'min', 'reduce', 'some'], function(funcName) { + _.each(['contains', 'createAggregator', 'every', 'filter', 'find', 'forEach', 'forEachRight', 'map', 'max', 'min', 'reduce', 'some'], function(funcName) { _.pull(funcDepMap[funcName], 'baseEach').push('forOwn'); }); @@ -3233,7 +3227,7 @@ // replace `+new Date` with `Date.now` use in `_.debounce source = source.replace(matchFunction(source, 'debounce'), function(match) { - return match.replace(/\+new Date\b/g, 'now()'); + return match.replace(/\+?new Date\b/g, 'now()'); }); // remove `shimIsPlainObject` from `_.isPlainObject` @@ -3286,6 +3280,29 @@ '}', ].join('\n')); + // replace `_.forEachRight` + source = replaceFunction(source, 'forEachRight', [ + 'function forEachRight(collection, callback, thisArg) {', + ' var length = collection ? collection.length : 0;', + " callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);", + " if (typeof length == 'number') {", + ' while (length--) {', + ' if (callback(collection[length], length, collection) === false) {', + ' break;', + ' }', + ' }', + ' } else {', + ' var props = keys(collection);', + ' length = props.length;', + ' baseEach(collection, function(value, key, collection) {', + ' key = props ? props[--length] : --length;', + ' return callback(collection[key], key, collection);', + ' });', + ' }', + ' return collection;', + '}', + ].join('\n')); + // replace `_.isRegExp` if (!isUnderscore || (isUnderscore && isLodash('isRegExp'))) { source = replaceFunction(source, 'isRegExp', [ @@ -3334,7 +3351,7 @@ ].join('\n')); // replace `isArray(collection)` checks in "Collections" functions with simpler type checks - _.each(['every', 'filter', 'find', 'max', 'min', 'reduce', 'some'], function(funcName) { + _.each(['createAggregator', 'every', 'filter', 'find', 'max', 'min', 'reduce', 'some'], function(funcName) { source = source.replace(matchFunction(source, funcName), function(match) { if (funcName == 'reduce') { match = match.replace(/^( *)var noaccum\b/m, '$1if (!collection) return accumulator;\n$&'); diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 2d1c5e521..439e7919f 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -1382,10 +1382,20 @@ return function(collection, callback, thisArg) { var result = {}; callback = lodash.createCallback(callback, thisArg, 3); - forEach(collection, function(value, key, collection) { - key = String(callback(value, key, collection)); - setter(result, value, key, collection); - }); + + if (isArray(collection)) { + var index = -1, + length = collection.length; + + while (++index < length) { + var value = collection[index]; + setter(result, value, callback(value, index, collection), collection); + } + } else { + baseEach(collection, function(value, key, collection) { + setter(result, value, callback(value, key, collection), collection); + }); + } return result; }; } @@ -1418,18 +1428,31 @@ isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32; + isPartialRight = bitmask & 32, + key = func; if (!isBindKey && !isFunction(func)) { throw new TypeError; } + if (isPartial && !partialArgs.length) { + bitmask &= ~16; + isPartial = partialArgs = false; + } + if (isPartialRight && !partialRightArgs.length) { + bitmask &= ~32; + isPartialRight = partialRightArgs = false; + } // use `Function#bind` if it exists and is fast // (in V8 `Function#bind` is slower except when partially applied) if (isBind && !(isBindKey || isCurry || isPartialRight) && - (support.fastBind || (nativeBind && partialArgs.length))) { - var args = [func, thisArg]; - push.apply(args, partialArgs); - var bound = nativeBind.call.apply(nativeBind, args); + (support.fastBind || (nativeBind && isPartial))) { + if (isPartial) { + var args = [thisArg]; + push.apply(args, partialArgs); + } + var bound = isPartial + ? nativeBind.apply(func, args) + : nativeBind.call(func, thisArg); } else { bound = function() { @@ -1438,14 +1461,14 @@ var args = arguments, thisBinding = isBind ? thisArg : this; - if (partialArgs) { + if (isPartial) { unshift.apply(args, partialArgs); } - if (partialRightArgs) { + if (isPartialRight) { push.apply(args, partialRightArgs); } if (isCurry && args.length < arity) { - bitmask |= 16 & ~32 + bitmask |= 16 & ~32; return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); } if (isBindKey) { @@ -1463,10 +1486,6 @@ return func.apply(thisBinding, args); }; } - if (isBindKey) { - var key = thisArg; - thisArg = func; - } return bound; } @@ -3285,17 +3304,25 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length != 'number') { - var props = keys(collection); - length = props.length; - } else if (support.unindexedChars && isString(collection)) { - iterable = collection.split(''); + callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); + if (isArray(collection)) { + while (length--) { + if (callback(collection[length], length, collection) === false) { + break; + } + } + } else { + if (typeof length != 'number') { + var props = keys(collection); + length = props.length; + } else if (support.unindexedChars && isString(collection)) { + iterable = collection.split(''); + } + baseEach(collection, function(value, key, collection) { + key = props ? props[--length] : --length; + return callback(iterable[key], key, collection); + }); } - callback = baseCreateCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { - index = props ? props[--length] : --length; - return callback(iterable[index], index, collection); - }); return collection; } @@ -4317,7 +4344,7 @@ var index = sortedIndex(array, value); return array[index] === value ? index : -1; } - return array ? baseIndexOf(array, value, fromIndex) : -1; + return baseIndexOf(array, value, fromIndex); } /** @@ -5083,7 +5110,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = bind(object[key], object); + object[key] = createBound(object[key], 1, null, null, object); } return object; } @@ -5123,7 +5150,7 @@ * // => 'hi, moe!' */ function bindKey(object, key) { - return createBound(object, 19, nativeSlice.call(arguments, 2), null, key); + return createBound(key, 19, nativeSlice.call(arguments, 2), null, object); } /** @@ -5319,6 +5346,7 @@ function debounce(func, wait, options) { var args, result, + stamp, thisArg, callCount = 0, lastCalled = 0, @@ -5339,24 +5367,30 @@ maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); trailing = 'trailing' in options ? options.trailing : trailing; } - var clear = function() { - clearTimeout(maxTimeoutId); - clearTimeout(timeoutId); - callCount = 0; - maxTimeoutId = timeoutId = null; - }; - var delayed = function() { - var isCalled = trailing && (!leading || callCount > 1); - clear(); - if (isCalled) { - lastCalled = +new Date; - result = func.apply(thisArg, args); + var remaining = wait - (new Date - stamp); + if (remaining <= 0) { + var isCalled = trailing && (!leading || callCount > 1); + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + } + callCount = 0; + maxTimeoutId = timeoutId = null; + if (isCalled) { + lastCalled = +new Date; + result = func.apply(thisArg, args); + } + } else { + timeoutId = setTimeout(delayed, remaining); } }; var maxDelayed = function() { - clear(); + if (timeoutId) { + clearTimeout(timeoutId); + } + callCount = 0; + maxTimeoutId = timeoutId = null; if (trailing || (maxWait !== wait)) { lastCalled = +new Date; result = func.apply(thisArg, args); @@ -5365,26 +5399,24 @@ return function() { args = arguments; + stamp = +new Date; thisArg = this; callCount++; - // 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); - if (maxWait === false) { if (leading && callCount < 2) { result = func.apply(thisArg, args); } } else { - var stamp = +new Date; if (!maxTimeoutId && !leading) { lastCalled = stamp; } var remaining = maxWait - (stamp - lastCalled); if (remaining <= 0) { - clearTimeout(maxTimeoutId); - maxTimeoutId = null; + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + maxTimeoutId = null; + } lastCalled = stamp; result = func.apply(thisArg, args); } @@ -5392,7 +5424,7 @@ maxTimeoutId = setTimeout(maxDelayed, remaining); } } - if (wait !== maxWait) { + if (!timeoutId && wait !== maxWait) { timeoutId = setTimeout(delayed, wait); } return result; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 6bf3f946f..64b0692de 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -11,27 +11,27 @@ }function tt(n,t,e,r,u,o){if(e){var a=e(n,t);if(typeof a!="undefined")return!!a}if(n===t)return 0!==n||1/n==1/t;if(n===n&&(!n||!Q[typeof n])&&(!t||!Q[typeof t]))return d;if(n==m||t==m)return n===t;var f=ke.call(n),c=ke.call(t);if(f==L&&(f=M),c==L&&(c=M),f!=c)return d;switch(f){case q:case K:return+n==+t;case J:return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case H:case U:return n==ue(t)}if(c=f==T,!c){if(me.call(n,"__wrapped__")||me.call(t,"__wrapped__"))return tt(n.__wrapped__||n,t.__wrapped__||t,e,r,u,o); if(f!=M||!Te.nodeClass&&(l(n)||l(t)))return d;var f=!Te.argsObject&>(n)?ee:n.constructor,s=!Te.argsObject&>(t)?ee:t.constructor;if(f!=s&&(!mt(f)||!(f instanceof f&&mt(s)&&s instanceof s)))return d}for(s=!u,u||(u=i()),o||(o=i()),f=u.length;f--;)if(u[f]==n)return o[f]==t;var g=0,a=y;if(u.push(n),o.push(t),c){if(f=n.length,g=t.length,a=g==n.length,!a&&!r)return a;for(;g--;)if(c=f,s=t[g],r)for(;c--&&!(a=tt(n[c],s,e,r,u,o)););else if(!(a=tt(n[g],s,e,r,u,o)))break;return a}return nr(t,function(t,i,f){return me.call(f,i)?(g++,a=me.call(n,i)&&tt(n[i],t,e,r,u,o)):void 0 }),a&&!r&&nr(n,function(n,t,e){return me.call(e,t)?a=-1<--g:void 0}),s&&(p(u),p(o)),a}function rt(n,t,e,r,u){(qe(t)?Et:tr)(t,function(t,o){var a,i,f=t,l=n[o];if(t&&((i=qe(t))||er(t))){for(f=r.length;f--;)if(a=r[f]==t){l=u[f];break}if(!a){var c;e&&(f=e(l,t),c=typeof f!="undefined")&&(l=f),c||(l=i?qe(l)?l:[]:er(l)?l:{}),r.push(t),u.push(l),c||rt(l,t,e,r,u)}}else e&&(f=e(l,t),typeof f=="undefined"&&(f=t)),typeof f!="undefined"&&(l=f);n[o]=l})}function ut(e,r,u){var a=-1,f=ct(),l=e?e.length:0,c=[],g=!r&&l>=C&&f===n,h=u||g?i():c; -if(g){var v=o(h);v?(f=t,h=v):(g=d,h=u?h:(p(h),c))}for(;++af(h,y))&&((u||g)&&h.push(y),c.push(v))}return g?(p(h.b),s(h)):u&&p(h),c}function ot(n){return function(t,e,r){var u={};return e=b.createCallback(e,r,3),Et(t,function(t,r,o){r=ue(e(t,r,o)),n(u,t,r,o)}),u}}function at(n,t,e,r,u,o){var a=1&t,i=2&t,f=4&t,l=8&t,c=32&t;if(!i&&!mt(n))throw new oe;if(!a||i||f||c||!(Te.fastBind||Ce&&e.length))p=function(){var c=arguments,g=a?u:this;return e&&xe.apply(c,e),r&&de.apply(c,r),f&&c.lengthf(h,y))&&((u||g)&&h.push(y),c.push(v))}return g?(p(h.b),s(h)):u&&p(h),c}function ot(n){return function(t,e,r){var u={};if(e=b.createCallback(e,r,3),qe(t)){r=-1;for(var o=t.length;++rk;k++)r+="n='"+n.h[k]+"';if((!(r&&x[n])&&m.call(t,n))",n.j||(r+="||(!x[n]&&t[n]!==A[n])"),r+="){"+n.g+"}"; r+="}"}return(n.b||Te.nonEnumArgs)&&(r+="}"),r+=n.c+";return E",t=t("d,j,k,m,o,p,q,s,v,A,B,y,I,J,L",e+r+"}"),s(n),t(X,W,ie,me,j,gt,qe,_t,n.f,fe,Q,Le,U,le,ke)}function ft(n){return dt(n)?Ee(n):{}}function lt(n){return He[n]}function ct(){var t=(t=b.indexOf)===$t?n:t;return t}function pt(n){var t,e;return!n||ke.call(n)!=M||(t=n.constructor,mt(t)&&!(t instanceof t))||!Te.argsClass&>(n)||!Te.nodeClass&&l(n)?d:Te.ownLast?(nr(n,function(n,t,r){return e=me.call(r,t),d}),e!==false):(nr(n,function(n,t){e=t }),e===v||me.call(n,e))}function st(n){return Ue[n]}function gt(n){return n&&typeof n=="object"?ke.call(n)==L:d}function ht(n,t,e){var r=We(n),u=r.length;for(t=X(t,e,3);u--&&(e=r[u],!(t(n[e],e,n)===false)););return n}function vt(n){var t=[];return nr(n,function(n,e){mt(n)&&t.push(e)}),t.sort()}function yt(n){for(var t=-1,e=We(n),r=e.length,u={};++te?Be(0,o+e):e)||0,o&&typeof o=="number"?a=-1<(_t(n)?n.indexOf(t,e):u(n,t,e)):Xe(n,function(n){return++ro&&(o=i) -}}else t=!t&&_t(n)?r:b.createCallback(t,e,3),Xe(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function It(n,t,e,r){var u=3>arguments.length;if(t=X(t,r,4),qe(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=X(t,r,4),Ot(n,function(n,r,o){e=u?(u=d,n):t(e,n,r,o)}),e}function Pt(n){var t=-1,e=n?n.length:0,r=Qt(typeof e=="number"?e:0);return Et(n,function(n){var e=Ut(++t); -r[t]=r[e],r[e]=n}),r}function Nt(n,t,e){var r;if(t=b.createCallback(t,e,3),qe(n)){e=-1;for(var u=n.length;++e=C&&u===n;if(l){var c=o(i);c?(u=t,i=c):l=d}for(;++ru(i,c)&&f.push(c);return l&&s(i),f}function Dt(n,t,e){if(n){var r=0,u=n.length; -if(typeof t!="number"&&t!=m){var o=-1;for(t=b.createCallback(t,e,3);++or?Be(0,u+r):r||0}else if(r)return r=Lt(t,e),t[r]===e?r:-1;return t?n(t,e,r):-1}function zt(n,t,e){if(typeof t!="number"&&t!=m){var r=0,u=-1,o=n?n.length:0;for(t=b.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++tl&&(i=n.apply(f,a));else{var e=+new Yt;!s&&!v&&(c=e);var o=p-(e-c);0o&&(o=i)}}else t=!t&&_t(n)?r:b.createCallback(t,e,3),Xe(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function It(n,t,e,r){var u=3>arguments.length;if(t=X(t,r,4),qe(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=X(t,r,4),Ot(n,function(n,r,o){e=u?(u=d,n):t(e,n,r,o)}),e}function Pt(n){var t=-1,e=n?n.length:0,r=Qt(typeof e=="number"?e:0); +return Et(n,function(n){var e=Ut(++t);r[t]=r[e],r[e]=n}),r}function Nt(n,t,e){var r;if(t=b.createCallback(t,e,3),qe(n)){e=-1;for(var u=n.length;++e=C&&u===n;if(l){var c=o(i);c?(u=t,i=c):l=d}for(;++ru(i,c)&&f.push(c);return l&&s(i),f +}function Dt(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=m){var o=-1;for(t=b.createCallback(t,e,3);++or?Be(0,u+r):r||0}else if(r)return r=Lt(t,e),t[r]===e?r:-1;return n(t,e,r)}function zt(n,t,e){if(typeof t!="number"&&t!=m){var r=0,u=-1,o=n?n.length:0;for(t=b.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++tl&&(a=n.apply(f,o)); +else{!s&&!v&&(c=i);var e=p-(i-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:b}},Ee||(ft=function(n){if(dt(n)){c.prototype=n;var t=new c;c.prototype=m}return t||{}}),Te.argsClass||(gt=function(n){return n&&typeof n=="object"?me.call(n,"callee"):d});var qe=Oe||function(n){return n&&typeof n=="object"?ke.call(n)==T:d},Ke=it({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),We=Ie?function(n){return dt(n)?Te.enumPrototypes&&typeof n=="function"||Te.nonEnumArgs&&n.length&>(n)?Ke(n):Ie(n):[] }:Ke,Ge={a:"g,e,K",i:"e=e&&typeof K=='undefined'?e:d(e,K,3)",b:"typeof u=='number'",v:We,g:"if(e(t[n],n,g)===false)return E"},Je={a:"z,H,l",i:"var a=arguments,b=0,c=typeof l=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Ue=yt(He),Ve=re("("+We(Ue).join("|")+")","g"),Qe=re("["+We(He).join("")+"]","g"),Xe=it(Ge),Ye=it(Je,{i:Je.i.replace(";",";if(c>3&&typeof a[c-2]=='function'){var e=d(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){e=a[--c]}"),g:"E[n]=e?e(E[n],t[n]):t[n]"}),Ze=it(Je),nr=it(Ge,Me,{j:d}),tr=it(Ge,Me); mt(/x/)&&(mt=function(n){return typeof n=="function"&&ke.call(n)==G});var er=ye?function(n){if(!n||ke.call(n)!=M||!Te.argsClass&>(n))return d;var t=n.valueOf,e=typeof t=="function"&&(e=ye(t))&&ye(e);return e?n==e||ye(n)==e:pt(n)}:pt,rr=ot(function(n,t,e){me.call(n,e)?n[e]++:n[e]=1}),ur=ot(function(n,t,e){(me.call(n,e)?n[e]:n[e]=[]).push(t)}),or=ot(function(n,t,e){n[e]=t}),ar=St;$e&&nt&&typeof _e=="function"&&(Jt=function(n){if(!mt(n))throw new oe;return _e.apply(e,arguments)});var ir=8==Ne(O+"08")?Ne:function(n,t){return Ne(_t(n)?n.replace(R,""):n,t||0) -};return b.after=function(n,t){if(!mt(t))throw new oe;return function(){return 1>--n?t.apply(this,arguments):void 0}},b.assign=Ye,b.at=function(n){var t=arguments,e=-1,r=Z(t,y,d,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Qt(t);for(Te.unindexedChars&&_t(n)&&(n=n.split(""));++e--n?t.apply(this,arguments):void 0}},b.assign=Ye,b.at=function(n){var t=arguments,e=-1,r=Z(t,y,d,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Qt(t);for(Te.unindexedChars&&_t(n)&&(n=n.split(""));++e logs each number from right to left and returns '3,2,1' */ function forEachRight(collection, callback, thisArg) { - var iterable = collection, - length = collection ? collection.length : 0; - - if (typeof length != 'number') { + var length = collection ? collection.length : 0; + callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); + if (typeof length == 'number') { + while (length--) { + if (callback(collection[length], length, collection) === false) { + break; + } + } + } else { var props = keys(collection); length = props.length; + forOwn(collection, function(value, key, collection) { + key = props ? props[--length] : --length; + return callback(collection[key], key, collection); + }); } - callback = baseCreateCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { - index = props ? props[--length] : --length; - return callback(iterable[index], index, collection); - }); return collection; } @@ -4014,7 +4035,7 @@ var index = sortedIndex(array, value); return array[index] === value ? index : -1; } - return array ? baseIndexOf(array, value, fromIndex) : -1; + return baseIndexOf(array, value, fromIndex); } /** @@ -4780,7 +4801,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = bind(object[key], object); + object[key] = createBound(object[key], 1, null, null, object); } return object; } @@ -4820,7 +4841,7 @@ * // => 'hi, moe!' */ function bindKey(object, key) { - return createBound(object, 19, nativeSlice.call(arguments, 2), null, key); + return createBound(key, 19, nativeSlice.call(arguments, 2), null, object); } /** @@ -5016,6 +5037,7 @@ function debounce(func, wait, options) { var args, result, + stamp, thisArg, callCount = 0, lastCalled = 0, @@ -5036,24 +5058,30 @@ maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); trailing = 'trailing' in options ? options.trailing : trailing; } - var clear = function() { - clearTimeout(maxTimeoutId); - clearTimeout(timeoutId); - callCount = 0; - maxTimeoutId = timeoutId = null; - }; - var delayed = function() { - var isCalled = trailing && (!leading || callCount > 1); - clear(); - if (isCalled) { - lastCalled = now(); - result = func.apply(thisArg, args); + var remaining = wait - (now() - stamp); + if (remaining <= 0) { + var isCalled = trailing && (!leading || callCount > 1); + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + } + callCount = 0; + maxTimeoutId = timeoutId = null; + if (isCalled) { + lastCalled = now(); + result = func.apply(thisArg, args); + } + } else { + timeoutId = setTimeout(delayed, remaining); } }; var maxDelayed = function() { - clear(); + if (timeoutId) { + clearTimeout(timeoutId); + } + callCount = 0; + maxTimeoutId = timeoutId = null; if (trailing || (maxWait !== wait)) { lastCalled = now(); result = func.apply(thisArg, args); @@ -5062,26 +5090,24 @@ return function() { args = arguments; + stamp = now(); thisArg = this; callCount++; - // 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); - if (maxWait === false) { if (leading && callCount < 2) { result = func.apply(thisArg, args); } } else { - var stamp = now(); if (!maxTimeoutId && !leading) { lastCalled = stamp; } var remaining = maxWait - (stamp - lastCalled); if (remaining <= 0) { - clearTimeout(maxTimeoutId); - maxTimeoutId = null; + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + maxTimeoutId = null; + } lastCalled = stamp; result = func.apply(thisArg, args); } @@ -5089,7 +5115,7 @@ maxTimeoutId = setTimeout(maxDelayed, remaining); } } - if (wait !== maxWait) { + if (!timeoutId && wait !== maxWait) { timeoutId = setTimeout(delayed, wait); } return result; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 094215e60..fffc2f8c1 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,50 +3,50 @@ * Lo-Dash 1.3.1 (Custom Build) lodash.com/license | Underscore.js 1.5.1 underscorejs.org/LICENSE * Build: `lodash modern -o ./dist/lodash.js` */ -;!function(){function n(n,t,r){r=(r||0)-1;for(var e=n?n.length:0;++re||typeof r=="undefined")return 1;if(rr?0:r);++e=j&&f===n,h=u||v?a():s;if(v){var g=o(h);g?(f=t,h=g):(v=m,h=u?h:(c(h),s)) -}for(;++if(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.b),p(h)):u&&c(h),s}function at(n){return function(t,r,e){var u={};return r=Z.createCallback(r,e,3),Ot(t,function(t,e,o){e=or(r(t,e,o)),n(u,t,e,o)}),u}}function ft(n,t,r,e,u,o){var i=1&t,a=2&t,f=4&t,l=8&t,c=16&t,p=32&t;if(!a&&!mt(n))throw new ir;var s=n&&n.__bindData__;if(s)return i&&!(1&s[1])&&(s[4]=u),!i&&1&s[1]&&(t|=8),f&&!(4&s[1])&&(s[5]=o),c&&br.apply(s[2]||(s[2]=[]),r),p&&br.apply(s[3]||(s[3]=[]),e),s[1]|=t,ft.apply(y,s); -if(!i||a||f||p||!(qr.fastBind||Cr&&r.length))v=function(){var c=arguments,p=i?u:this;return r&&xr.apply(c,r),e&&br.apply(c,e),f&&c.lengthr?Nr(0,o+r):r)||0,o&&typeof o=="number"?i=-1<(dt(n)?n.indexOf(t,r):u(n,t,r)):b(n,function(n){return++eo&&(o=a)}}else t=!t&&dt(n)?e:Z.createCallback(t,r,3),Ot(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n) -});return o}function At(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Xt(e);++rarguments.length;t=rt(t,e,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(r=n[++o]);++oarguments.length;return t=rt(t,e,4),Et(n,function(n,e,o){r=u?(u=m,n):t(r,n,e,o)}),r}function Bt(n){var t=-1,r=n?n.length:0,e=Xt(typeof r=="number"?r:0); -return Ot(n,function(n){var r=Jt(++t);e[t]=e[r],e[r]=n}),e}function $t(n,t,r){var e;t=Z.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=j&&u===n;if(l){var c=o(a);c?(u=t,a=c):l=m}for(;++eu(a,c)&&f.push(c);return l&&p(a),f}function Tt(n,t,r){if(n){var e=0,u=n.length; -if(typeof t!="number"&&t!=y){var o=-1;for(t=Z.createCallback(t,r,3);++oe?Nr(0,u+e):e||0}else if(e)return e=Wt(t,r),t[e]===r?e:-1;return t?n(t,r,e):-1}function qt(n,t,r){if(typeof t!="number"&&t!=y){var e=0,u=-1,o=n?n.length:0;for(t=Z.createCallback(t,r,3);++u>>1,r(n[e])r?0:r);++tl&&(a=n.apply(f,i));else{var r=_r();!s&&!_&&(c=r);var o=p-(r-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:A,variable:"",imports:{_:Z}}; -var Wr=vr?function(n,t){var r=f();r.value=t,vr(n,"__bindData__",r),p(r)}:l,Pr=Er||function(n){return n&&typeof n=="object"?kr.call(n)==T:m},Kr=Ar?function(n){return _t(n)?Ar(n):[]}:X,Lr={"&":"&","<":"<",">":">",'"':""","'":"'"},Mr=yt(Lr),Ur=ur("("+Kr(Mr).join("|")+")","g"),Vr=ur("["+Kr(Lr).join("")+"]","g"),Gr=at(function(n,t,r){mr.call(n,r)?n[r]++:n[r]=1}),Hr=at(function(n,t,r){(mr.call(n,r)?n[r]:n[r]=[]).push(t)}),Jr=at(function(n,t,r){n[r]=t});Tr&&Q&&typeof dr=="function"&&(Vt=function(n){if(!mt(n))throw new ir; -return dr.apply(r,arguments)});var Qr=8==Br(x+"08")?Br:function(n,t){return Br(dt(n)?n.replace(N,""):n,t||0)};return Z.after=function(n,t){if(!mt(t))throw new ir;return function(){return 1>--n?t.apply(this,arguments):void 0}},Z.assign=J,Z.at=function(n){for(var t=arguments,r=-1,e=et(t,g,m,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=Xt(t);++r=j&&o(i?e[i]:g)}n:for(;++l(m?t(m,y):s(g,y))){for(i=u,(m||g).push(y);--i;)if(m=f[i],0>(m?t(m,y):s(e[i],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&p(m);return c(f),c(g),h},Z.invert=yt,Z.invoke=function(n,t){var r=Dr.call(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Xt(typeof o=="number"?o:0);return Ot(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},Z.keys=Kr,Z.map=It,Z.max=St,Z.memoize=function(n,t){function r(){var e=r.cache,u=t?t.apply(this,arguments):w+arguments[0]; -return mr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)}if(!mt(n))throw new ir;return r.cache={},r},Z.merge=function(n){var t=arguments,r=2;if(!_t(n))return n;if("number"!=typeof t[2]&&(r=t.length),3e(i,r))&&(o[r]=n)}),o},Z.once=function(n){var t,r;if(!mt(n))throw new ir;return function(){return t?r:(t=g,r=n.apply(this,arguments),n=y,r)}},Z.pairs=function(n){for(var t=-1,r=Kr(n),e=r.length,u=Xt(e);++tr?Nr(0,e+r):Rr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},Z.mixin=Ht,Z.noConflict=function(){return r._=lr,this},Z.parseInt=Qr,Z.random=Jt,Z.reduce=Nt,Z.reduceRight=Rt,Z.result=function(n,t){var r=n?n[t]:h;return mt(r)?n[t]():r},Z.runInContext=v,Z.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Kr(n).length},Z.some=$t,Z.sortedIndex=Wt,Z.template=function(n,t,r){var e=Z.templateSettings; -n||(n=""),r=G({},r,e);var u,o=G({},r.imports,e.imports),e=Kr(o),o=wt(o),a=0,f=r.interpolate||R,l="__p+='",f=ur((r.escape||R).source+"|"+f.source+"|"+(f===A?I:R).source+"|"+(r.evaluate||R).source+"|$","g");n.replace(f,function(t,r,e,o,f,c){return e||(e=o),l+=n.slice(a,c).replace($,i),r&&(l+="'+__e("+r+")+'"),f&&(u=g,l+="';"+f+";__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),a=c+t.length,t}),l+="';\n",f=r=r.variable,f||(r="obj",l="with("+r+"){"+l+"}"),l=(u?l.replace(C,""):l).replace(O,"$1").replace(E,"$1;"),l="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}"; -try{var c=nr(e,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Z.unescape=function(n){return n==y?"":or(n).replace(Ur,st)},Z.uniqueId=function(n){var t=++d;return or(n==y?"":n)+t},Z.all=kt,Z.any=$t,Z.detect=Ct,Z.findWhere=Ct,Z.foldl=Nt,Z.foldr=Rt,Z.include=jt,Z.inject=Nt,b(Z,function(n,t){Z.prototype[t]||(Z.prototype[t]=function(){var t=[this.__wrapped__],r=this.__chain__;return br.apply(t,arguments),t=n.apply(Z,t),r?new nt(t,r):t})}),Z.first=Tt,Z.last=function(n,t,r){if(n){var e=0,u=n.length; -if(typeof t!="number"&&t!=y){var o=u;for(t=Z.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,e==y||r)return n[u-1];return s(n,Nr(0,u-e))}},Z.sample=function(n,t,r){return Pr(n)||(n=Dt(n)),t==y||r?n[Jt(n.length-1)]:(n=Bt(n),n.length=Rr(Nr(0,t),n.length),n)},Z.take=Tt,Z.head=Tt,b(Z,function(n,t){var r="sample"!==t;Z.prototype[t]||(Z.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||t!=y&&(!e||r&&typeof t=="function")?new nt(o,u):o})}),Z.VERSION="1.3.1",Z.prototype.chain=function(){return this.__chain__=g,this -},Z.prototype.toString=function(){return or(this.__wrapped__)},Z.prototype.value=Qt,Z.prototype.valueOf=Qt,Ot(["join","pop","shift"],function(n){var t=ar[n];Z.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments);return n?new nt(r,n):r}}),Ot(["push","reverse","sort","unshift"],function(n){var t=ar[n];Z.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ot(["concat","slice","splice"],function(n){var t=ar[n];Z.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__) +;!function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++er||typeof e=="undefined")return 1;if(ee?0:e);++r=j&&f===n,h=u||v?a():s;if(v){var g=o(h);g?(f=t,h=g):(v=m,h=u?h:(c(h),s)) +}for(;++if(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.b),p(h)):u&&c(h),s}function at(n){return function(t,e,r){var u={};e=Z.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Ne(0,o+e):e)||0,o&&typeof o=="number"?i=-1<(dt(n)?n.indexOf(t,e):u(n,t,e)):b(n,function(n){return++ro&&(o=a)}}else t=!t&&dt(n)?r:Z.createCallback(t,e,3),Ot(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function At(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Xt(r);++earguments.length;t=et(t,r,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(e=n[++o]);++oarguments.length;return t=et(t,r,4),Et(n,function(n,r,o){e=u?(u=m,n):t(e,n,r,o)}),e}function Bt(n){var t=-1,e=n?n.length:0,r=Xt(typeof e=="number"?e:0);return Ot(n,function(n){var e=Jt(++t);r[t]=r[e],r[e]=n}),r}function $t(n,t,e){var r;t=Z.createCallback(t,e,3),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++e=j&&u===n;if(l){var c=o(a);c?(u=t,a=c):l=m}for(;++ru(a,c)&&f.push(c);return l&&p(a),f}function Tt(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=y){var o=-1;for(t=Z.createCallback(t,e,3);++or?Ne(0,u+r):r||0}else if(r)return r=Wt(t,e),t[r]===e?r:-1;return n(t,e,r) +}function qt(n,t,e){if(typeof t!="number"&&t!=y){var r=0,u=-1,o=n?n.length:0;for(t=Z.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++tl&&(i=n.apply(f,o));else{!s&&!_&&(c=a);var e=p-(a-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:A,variable:"",imports:{_:Z}}; +var We=ve?function(n,t){var e=f();e.value=t,ve(n,"__bindData__",e),p(e)}:l,Pe=Ee||function(n){return n&&typeof n=="object"?ke.call(n)==T:m},Ke=Ae?function(n){return _t(n)?Ae(n):[]}:X,Le={"&":"&","<":"<",">":">",'"':""","'":"'"},Me=yt(Le),Ue=ue("("+Ke(Me).join("|")+")","g"),Ve=ue("["+Ke(Le).join("")+"]","g"),Ge=at(function(n,t,e){me.call(n,e)?n[e]++:n[e]=1}),He=at(function(n,t,e){(me.call(n,e)?n[e]:n[e]=[]).push(t)}),Je=at(function(n,t,e){n[e]=t});Te&&Q&&typeof de=="function"&&(Vt=function(n){if(!mt(n))throw new ie; +return de.apply(e,arguments)});var Qe=8==Be(x+"08")?Be:function(n,t){return Be(dt(n)?n.replace(N,""):n,t||0)};return Z.after=function(n,t){if(!mt(t))throw new ie;return function(){return 1>--n?t.apply(this,arguments):void 0}},Z.assign=J,Z.at=function(n){for(var t=arguments,e=-1,r=rt(t,g,m,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Xt(t);++e=j&&o(i?r[i]:g)}n:for(;++l(m?t(m,y):s(g,y))){for(i=u,(m||g).push(y);--i;)if(m=f[i],0>(m?t(m,y):s(r[i],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&p(m);return c(f),c(g),h},Z.invert=yt,Z.invoke=function(n,t){var e=De.call(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,i=Xt(typeof o=="number"?o:0);return Ot(n,function(n){i[++r]=(u?t:n[t]).apply(n,e)}),i},Z.keys=Ke,Z.map=It,Z.max=St,Z.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):w+arguments[0]; +return me.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!mt(n))throw new ie;return e.cache={},e},Z.merge=function(n){var t=arguments,e=2;if(!_t(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(i,e))&&(o[e]=n)}),o},Z.once=function(n){var t,e;if(!mt(n))throw new ie;return function(){return t?e:(t=g,e=n.apply(this,arguments),n=y,e)}},Z.pairs=function(n){for(var t=-1,e=Ke(n),r=e.length,u=Xt(r);++te?Ne(0,r+e):Re(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},Z.mixin=Ht,Z.noConflict=function(){return e._=le,this},Z.parseInt=Qe,Z.random=Jt,Z.reduce=Nt,Z.reduceRight=Rt,Z.result=function(n,t){var e=n?n[t]:h;return mt(e)?n[t]():e},Z.runInContext=v,Z.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Ke(n).length},Z.some=$t,Z.sortedIndex=Wt,Z.template=function(n,t,e){var r=Z.templateSettings; +n||(n=""),e=G({},e,r);var u,o=G({},e.imports,r.imports),r=Ke(o),o=wt(o),a=0,f=e.interpolate||R,l="__p+='",f=ue((e.escape||R).source+"|"+f.source+"|"+(f===A?I:R).source+"|"+(e.evaluate||R).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(a,c).replace($,i),e&&(l+="'+__e("+e+")+'"),f&&(u=g,l+="';"+f+";__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),a=c+t.length,t}),l+="';\n",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(C,""):l).replace(O,"$1").replace(E,"$1;"),l="function("+e+"){"+(f?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}"; +try{var c=ne(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Z.unescape=function(n){return n==y?"":oe(n).replace(Ue,st)},Z.uniqueId=function(n){var t=++d;return oe(n==y?"":n)+t},Z.all=kt,Z.any=$t,Z.detect=Ct,Z.findWhere=Ct,Z.foldl=Nt,Z.foldr=Rt,Z.include=jt,Z.inject=Nt,b(Z,function(n,t){Z.prototype[t]||(Z.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return be.apply(t,arguments),t=n.apply(Z,t),e?new nt(t,e):t})}),Z.first=Tt,Z.last=function(n,t,e){if(n){var r=0,u=n.length; +if(typeof t!="number"&&t!=y){var o=u;for(t=Z.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,r==y||e)return n[u-1];return s(n,Ne(0,u-r))}},Z.sample=function(n,t,e){return Pe(n)||(n=Dt(n)),t==y||e?n[Jt(n.length-1)]:(n=Bt(n),n.length=Re(Ne(0,t),n.length),n)},Z.take=Tt,Z.head=Tt,b(Z,function(n,t){var e="sample"!==t;Z.prototype[t]||(Z.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||t!=y&&(!r||e&&typeof t=="function")?new nt(o,u):o})}),Z.VERSION="1.3.1",Z.prototype.chain=function(){return this.__chain__=g,this +},Z.prototype.toString=function(){return oe(this.__wrapped__)},Z.prototype.value=Qt,Z.prototype.valueOf=Qt,Ot(["join","pop","shift"],function(n){var t=ae[n];Z.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments);return n?new nt(e,n):e}}),Ot(["push","reverse","sort","unshift"],function(n){var t=ae[n];Z.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ot(["concat","slice","splice"],function(n){var t=ae[n];Z.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__) }}),Z}var h,g=!0,y=null,m=!1,_=[],b=[],d=0,w=+new Date+"",j=75,k=40,x=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",C=/\b__p\+='';/g,O=/\b(__p\+=)''\+/g,E=/(__e\(.*?\)|\b__t\))\+'';/g,I=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,S=/\w*$/,A=/<%=([\s\S]+?)%>/g,N=RegExp("^["+x+"]*0+(?=.$)"),R=/($^)/,B=(B=/\bthis\b/)&&B.test(v)&&B,$=/['\n\r\t\u2028\u2029\\]/g,D="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),F="[object Arguments]",T="[object Array]",z="[object Boolean]",q="[object Date]",W="[object Function]",P="[object Number]",K="[object Object]",L="[object RegExp]",M="[object String]",U={}; U[W]=m,U[F]=U[T]=U[z]=U[q]=U[P]=U[K]=U[L]=U[M]=g;var V={"boolean":m,"function":g,object:g,number:m,string:m,undefined:m},G={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},H=V[typeof window]&&window||this,J=V[typeof exports]&&exports,Q=V[typeof module]&&module&&module.exports==J&&module,X=V[typeof global]&&global;!X||X.global!==X&&X.window!==X||(H=X);var Y=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(H._=Y, define(function(){return Y})):J&&!J.nodeType?Q?(Q.exports=Y)._=Y:J._=Y:H._=Y }.call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index cce494589..ffa54499e 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -587,10 +587,20 @@ return function(collection, callback, thisArg) { var result = {}; callback = createCallback(callback, thisArg, 3); - forEach(collection, function(value, key, collection) { - key = String(callback(value, key, collection)); - setter(result, value, key, collection); - }); + + var index = -1, + length = collection ? collection.length : 0; + + if (typeof length == 'number') { + while (++index < length) { + var value = collection[index]; + setter(result, value, callback(value, index, collection), collection); + } + } else { + forOwn(collection, function(value, key, collection) { + setter(result, value, callback(value, key, collection), collection); + }); + } return result; }; } @@ -623,18 +633,31 @@ isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32; + isPartialRight = bitmask & 32, + key = func; if (!isBindKey && !isFunction(func)) { throw new TypeError; } + if (isPartial && !partialArgs.length) { + bitmask &= ~16; + isPartial = partialArgs = false; + } + if (isPartialRight && !partialRightArgs.length) { + bitmask &= ~32; + isPartialRight = partialRightArgs = false; + } // use `Function#bind` if it exists and is fast // (in V8 `Function#bind` is slower except when partially applied) if (isBind && !(isBindKey || isCurry || isPartialRight) && - (support.fastBind || (nativeBind && partialArgs.length))) { - var args = [func, thisArg]; - push.apply(args, partialArgs); - var bound = nativeBind.call.apply(nativeBind, args); + (support.fastBind || (nativeBind && isPartial))) { + if (isPartial) { + var args = [thisArg]; + push.apply(args, partialArgs); + } + var bound = isPartial + ? nativeBind.apply(func, args) + : nativeBind.call(func, thisArg); } else { bound = function() { @@ -643,14 +666,14 @@ var args = arguments, thisBinding = isBind ? thisArg : this; - if (partialArgs) { + if (isPartial) { unshift.apply(args, partialArgs); } - if (partialRightArgs) { + if (isPartialRight) { push.apply(args, partialRightArgs); } if (isCurry && args.length < arity) { - bitmask |= 16 & ~32 + bitmask |= 16 & ~32; return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); } if (isBindKey) { @@ -668,10 +691,6 @@ return func.apply(thisBinding, args); }; } - if (isBindKey) { - var key = thisArg; - thisArg = func; - } return bound; } @@ -1942,17 +1961,21 @@ * // => logs each number from right to left and returns '3,2,1' */ function forEachRight(collection, callback) { - var iterable = collection, - length = collection ? collection.length : 0; - - if (typeof length != 'number') { + var length = collection ? collection.length : 0; + if (typeof length == 'number') { + while (length--) { + if (callback(collection[length], length, collection) === false) { + break; + } + } + } else { var props = keys(collection); length = props.length; + forOwn(collection, function(value, key, collection) { + key = props ? props[--length] : --length; + return callback(collection[key], key, collection) === false && indicatorObject; + }); } - forEach(collection, function(value, index, collection) { - index = props ? props[--length] : --length; - return callback(iterable[index], index, collection) === false && indicatorObject; - }); } /** @@ -2825,7 +2848,7 @@ var index = sortedIndex(array, value); return array[index] === value ? index : -1; } - return array ? baseIndexOf(array, value, fromIndex) : -1; + return baseIndexOf(array, value, fromIndex); } /** @@ -3484,7 +3507,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = bind(object[key], object); + object[key] = createBound(object[key], 1, null, null, object); } return object; } @@ -3637,6 +3660,7 @@ function debounce(func, wait, options) { var args, result, + stamp, thisArg, callCount = 0, lastCalled = 0, @@ -3657,24 +3681,30 @@ maxWait = 'maxWait' in options && nativeMax(wait, options.maxWait || 0); trailing = 'trailing' in options ? options.trailing : trailing; } - var clear = function() { - clearTimeout(maxTimeoutId); - clearTimeout(timeoutId); - callCount = 0; - maxTimeoutId = timeoutId = null; - }; - var delayed = function() { - var isCalled = trailing && (!leading || callCount > 1); - clear(); - if (isCalled) { - lastCalled = +new Date; - result = func.apply(thisArg, args); + var remaining = wait - (new Date - stamp); + if (remaining <= 0) { + var isCalled = trailing && (!leading || callCount > 1); + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + } + callCount = 0; + maxTimeoutId = timeoutId = null; + if (isCalled) { + lastCalled = +new Date; + result = func.apply(thisArg, args); + } + } else { + timeoutId = setTimeout(delayed, remaining); } }; var maxDelayed = function() { - clear(); + if (timeoutId) { + clearTimeout(timeoutId); + } + callCount = 0; + maxTimeoutId = timeoutId = null; if (trailing || (maxWait !== wait)) { lastCalled = +new Date; result = func.apply(thisArg, args); @@ -3683,26 +3713,24 @@ return function() { args = arguments; + stamp = +new Date; thisArg = this; callCount++; - // 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); - if (maxWait === false) { if (leading && callCount < 2) { result = func.apply(thisArg, args); } } else { - var stamp = +new Date; if (!maxTimeoutId && !leading) { lastCalled = stamp; } var remaining = maxWait - (stamp - lastCalled); if (remaining <= 0) { - clearTimeout(maxTimeoutId); - maxTimeoutId = null; + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + maxTimeoutId = null; + } lastCalled = stamp; result = func.apply(thisArg, args); } @@ -3710,7 +3738,7 @@ maxTimeoutId = setTimeout(maxDelayed, remaining); } } - if (wait !== maxWait) { + if (!timeoutId && wait !== maxWait) { timeoutId = setTimeout(delayed, wait); } return result; diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index e1175c976..2df2e1beb 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -4,34 +4,35 @@ * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ ;!function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined")return 1;if(tu(a,l))&&(t&&a.push(l),o.push(f))}return o}function c(n){return function(r,t,e){var u={};return t=J(t,e,3),R(r,function(r,e,i){e=t(r,e,i)+"",n(u,r,e,i)}),u}}function p(n,r,t,e,u,i){var o=1&r,a=2&r,f=4&r,l=8&r,c=32&r; -if(!a&&!j(n))throw new TypeError;if(!o||a||f||c||!(zr.fastBind||Sr&&t.length))v=function(){var c=arguments,g=o?u:this;return t&&Or.apply(c,t),e&&Ar.apply(c,e),f&&c.lengthe&&(e=t,u=n)});else for(;++iu&&(u=t);return u}function q(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++targuments.length;r=o(r,e,4);var i=-1,a=n.length;if(typeof a=="number")for(u&&(t=n[++i]);++iarguments.length;return r=o(r,e,4),B(n,function(n,e,i){t=u?(u=!1,n):r(t,n,e,i)}),t}function I(n,r,t){var e;r=J(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++tt(u,o)&&i.push(o)}return i}function C(n,r,t){if(n){var e=0,u=n.length; -if(typeof r!="number"&&null!=r){var i=-1;for(r=J(r,t,3);++ie?Dr(0,u+e):e||0}else if(e)return e=V(r,t),r[e]===t?e:-1;return r?n(r,t,e):-1}function U(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,i=n?n.length:0;for(r=J(r,t,3);++u>>1,t(n[e])o&&(u=n.apply(i,e));else{var t=+new Date;!l&&!s&&(a=t);var p=f-(t-a);0u(f,l))&&(t&&f.push(l),o.push(a))}return o}function c(n){return function(r,t,e){var u={};t=J(t,e,3),e=-1;var i=r?r.length:0;if(typeof i=="number")for(;++ee&&(e=t,u=n)});else for(;++iu&&(u=t);return u}function q(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++targuments.length;r=o(r,e,4); +var i=-1,f=n.length;if(typeof f=="number")for(u&&(t=n[++i]);++iarguments.length;return r=o(r,e,4),B(n,function(n,e,i){t=u?(u=!1,n):r(t,n,e,i)}),t}function I(n,r,t){var e;r=J(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++tt(u,o)&&i.push(o)}return i}function C(n,r,t){if(n){var e=0,u=n.length;if(typeof r!="number"&&null!=r){var i=-1;for(r=J(r,t,3);++ie?kr(0,u+e):e||0}else if(e)return e=V(r,t),r[e]===t?e:-1;return n(r,t,e)}function U(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,i=n?n.length:0;for(r=J(r,t,3);++u>>1,t(n[e])f&&(u=n.apply(o,e)); +else{!c&&!v&&(a=i);var t=l-(i-a);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Fr||(s=function(n){if(x(n)){e.prototype=n;var r=new e;e.prototype=null}return r||{}}),y(arguments)||(y=function(n){return n&&typeof n=="object"?Er.call(n,"callee"):!1});var Cr=Nr||function(n){return n&&typeof n=="object"?Tr.call(n)==ir:!1},Pr=function(n){var r,t=[]; -if(!n||!sr[typeof n])return t;for(r in n)Er.call(n,r)&&t.push(r);return t},Ur=kr?function(n){return x(n)?kr(n):[]}:Pr,Vr={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Gr=b(Vr),Hr=RegExp("("+Ur(Gr).join("|")+")","g"),Jr=RegExp("["+Ur(Vr).join("")+"]","g"),Kr=function(n,r){var t;if(!n||!sr[typeof n])return n;for(t in n)if(r(n[t],t,n)===nr)break;return n},Lr=function(n,r){var t;if(!n||!sr[typeof n])return n;for(t in n)if(Er.call(n,t)&&r(n[t],t,n)===nr)break;return n};j(/x/)&&(j=function(n){return typeof n=="function"&&"[object Function]"==Tr.call(n) -});var Qr=c(function(n,r,t){Er.call(n,t)?n[t]++:n[t]=1}),Xr=c(function(n,r,t){(Er.call(n,t)?n[t]:n[t]=[]).push(r)});u.after=function(n,r){if(!j(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},u.bind=H,u.bindAll=function(n){for(var r=1u(o,a)){for(var f=t;--f;)if(0>u(r[f],a))continue n;o.push(a)}}return o},u.invert=b,u.invoke=function(n,r){var t=$r.call(arguments,2),e=-1,u=typeof r=="function",i=n?n.length:0,o=Array(typeof i=="number"?i:0); -return R(n,function(n){o[++e]=(u?r:n[r]).apply(n,t)}),o},u.keys=Ur,u.map=k,u.max=D,u.memoize=function(n,r){var t={};return function(){var e=rr+(r?r.apply(this,arguments):arguments[0]);return Er.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},u.min=function(n,r,t){var e=1/0,u=e,i=-1,o=n?n.length:0;if(r||typeof o!="number")r=J(r,t,3),R(n,function(n,t,i){t=r(n,t,i),tr(t,u)&&(e[u]=n) -}),e},u.once=function(n){var r,t;if(!j(n))throw new TypeError;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},u.pairs=function(n){for(var r=-1,t=Ur(n),e=t.length,u=Array(e);++r":">",'"':""","'":"'","/":"/"},Gr=b(Vr),Hr=RegExp("("+Ur(Gr).join("|")+")","g"),Jr=RegExp("["+Ur(Vr).join("")+"]","g"),Kr=function(n,r){var t;if(!n||!sr[typeof n])return n;for(t in n)if(r(n[t],t,n)===nr)break;return n},Lr=function(n,r){var t;if(!n||!sr[typeof n])return n;for(t in n)if(Er.call(n,t)&&r(n[t],t,n)===nr)break;return n};j(/x/)&&(j=function(n){return typeof n=="function"&&"[object Function]"==Tr.call(n) +});var Qr=c(function(n,r,t){Er.call(n,t)?n[t]++:n[t]=1}),Xr=c(function(n,r,t){(Er.call(n,t)?n[t]:n[t]=[]).push(r)});u.after=function(n,r){if(!j(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},u.bind=H,u.bindAll=function(n){for(var r=1u(o,f)){for(var a=t;--a;)if(0>u(r[a],f))continue n;o.push(f)}}return o},u.invert=b,u.invoke=function(n,r){var t=$r.call(arguments,2),e=-1,u=typeof r=="function",i=n?n.length:0,o=Array(typeof i=="number"?i:0); +return R(n,function(n){o[++e]=(u?r:n[r]).apply(n,t)}),o},u.keys=Ur,u.map=D,u.max=k,u.memoize=function(n,r){var t={};return function(){var e=rr+(r?r.apply(this,arguments):arguments[0]);return Er.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},u.min=function(n,r,t){var e=1/0,u=e,i=-1,o=n?n.length:0;if(r||typeof o!="number")r=J(r,t,3),R(n,function(n,t,i){t=r(n,t,i),tr(t,u)&&(e[u]=n) +}),e},u.once=function(n){var r,t;if(!j(n))throw new TypeError;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},u.pairs=function(n){for(var r=-1,t=Ur(n),e=t.length,u=Array(e);++rr?0:r);++nt?Dr(0,e+t):qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},u.mixin=Q,u.noConflict=function(){return hr._=br,this},u.random=X,u.reduce=M,u.reduceRight=$,u.result=function(n,r){var t=n?n[r]:Y;return j(t)?n[r]():t},u.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:Ur(n).length -},u.some=I,u.sortedIndex=V,u.template=function(n,r,e){var i=u,o=i.templateSettings;n||(n=""),e=_({},e,o);var a=0,f="__p+='",o=e.variable;n.replace(RegExp((e.escape||tr).source+"|"+(e.interpolate||tr).source+"|"+(e.evaluate||tr).source+"|$","g"),function(r,e,u,i,o){return f+=n.slice(a,o).replace(er,t),e&&(f+="'+_.escape("+e+")+'"),i&&(f+="';"+i+";__p+='"),u&&(f+="'+((__t=("+u+"))==null?'':__t)+'"),a=o+r.length,r}),f+="';\n",o||(o="obj",f="with("+o+"||{}){"+f+"}"),f="function("+o+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+f+"return __p}"; -try{var l=Function("_","return "+f)(i)}catch(c){throw c.source=f,c}return r?l(r):(l.source=f,l)},u.unescape=function(n){return null==n?"":(n+"").replace(Hr,g)},u.uniqueId=function(n){var r=++Z+"";return n?n+r:r},u.all=S,u.any=I,u.detect=N,u.findWhere=function(n,r){return W(n,r,!0)},u.foldl=M,u.foldr=$,u.include=O,u.inject=M,u.first=C,u.last=function(n,r,t){if(n){var e=0,u=n.length;if(typeof r!="number"&&null!=r){var i=u;for(r=J(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n[u-1];return $r.call(n,Dr(0,u-e)) +},u.throttle=function(n,r,t){var e=!0,u=!0;return false===t?e=!1:x(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),t={},t.leading=e,t.maxWait=r,t.trailing=u,K(n,r,t)},u.times=function(n,r,t){for(var e=-1,u=Array(-1r?0:r);++nt?kr(0,e+t):qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},u.mixin=Q,u.noConflict=function(){return hr._=br,this},u.random=X,u.reduce=M,u.reduceRight=$,u.result=function(n,r){var t=n?n[r]:Y;return j(t)?n[r]():t},u.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:Ur(n).length +},u.some=I,u.sortedIndex=V,u.template=function(n,r,e){var i=u,o=i.templateSettings;n||(n=""),e=_({},e,o);var f=0,a="__p+='",o=e.variable;n.replace(RegExp((e.escape||tr).source+"|"+(e.interpolate||tr).source+"|"+(e.evaluate||tr).source+"|$","g"),function(r,e,u,i,o){return a+=n.slice(f,o).replace(er,t),e&&(a+="'+_.escape("+e+")+'"),i&&(a+="';"+i+";__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=o+r.length,r}),a+="';\n",o||(o="obj",a="with("+o+"||{}){"+a+"}"),a="function("+o+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; +try{var l=Function("_","return "+a)(i)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},u.unescape=function(n){return null==n?"":(n+"").replace(Hr,g)},u.uniqueId=function(n){var r=++Z+"";return n?n+r:r},u.all=S,u.any=I,u.detect=N,u.findWhere=function(n,r){return W(n,r,!0)},u.foldl=M,u.foldr=$,u.include=O,u.inject=M,u.first=C,u.last=function(n,r,t){if(n){var e=0,u=n.length;if(typeof r!="number"&&null!=r){var i=u;for(r=J(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n[u-1];return $r.call(n,kr(0,u-e)) }},u.take=C,u.head=C,Q(u),u.VERSION="1.3.1",u.prototype.chain=function(){return this.__chain__=!0,this},u.prototype.value=function(){return this.__wrapped__},R("pop push reverse shift sort splice unshift".split(" "),function(n){var r=_r[n];u.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),!zr.spliceObjects&&0===n.length&&delete n[0],this}}),R(["concat","join","slice"],function(n){var r=_r[n];u.prototype[n]=function(){var n=r.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new i(n),n.__chain__=!0),n }}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(hr._=u, define(function(){return u})):gr&&!gr.nodeType?yr?(yr.exports=u)._=u:gr._=u:hr._=u}.call(this); \ No newline at end of file diff --git a/lodash.js b/lodash.js index b58861edc..3d9d1265e 100644 --- a/lodash.js +++ b/lodash.js @@ -1414,10 +1414,20 @@ return function(collection, callback, thisArg) { var result = {}; callback = lodash.createCallback(callback, thisArg, 3); - forEach(collection, function(value, key, collection) { - key = String(callback(value, key, collection)); - setter(result, value, key, collection); - }); + + if (isArray(collection)) { + var index = -1, + length = collection.length; + + while (++index < length) { + var value = collection[index]; + setter(result, value, callback(value, index, collection), collection); + } + } else { + baseEach(collection, function(value, key, collection) { + setter(result, value, callback(value, key, collection), collection); + }); + } return result; }; } @@ -1450,11 +1460,20 @@ isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32; + isPartialRight = bitmask & 32, + key = func; if (!isBindKey && !isFunction(func)) { throw new TypeError; } + if (isPartial && !partialArgs.length) { + bitmask &= ~16; + isPartial = partialArgs = false; + } + if (isPartialRight && !partialRightArgs.length) { + bitmask &= ~32; + isPartialRight = partialRightArgs = false; + } var bindData = func && func.__bindData__; if (bindData) { if (isBind && !(bindData[1] & 1)) { @@ -1478,10 +1497,14 @@ // use `Function#bind` if it exists and is fast // (in V8 `Function#bind` is slower except when partially applied) if (isBind && !(isBindKey || isCurry || isPartialRight) && - (support.fastBind || (nativeBind && partialArgs.length))) { - var args = [func, thisArg]; - push.apply(args, partialArgs); - var bound = nativeBind.call.apply(nativeBind, args); + (support.fastBind || (nativeBind && isPartial))) { + if (isPartial) { + var args = [thisArg]; + push.apply(args, partialArgs); + } + var bound = isPartial + ? nativeBind.apply(func, args) + : nativeBind.call(func, thisArg); } else { bound = function() { @@ -1490,14 +1513,14 @@ var args = arguments, thisBinding = isBind ? thisArg : this; - if (partialArgs) { + if (isPartial) { unshift.apply(args, partialArgs); } - if (partialRightArgs) { + if (isPartialRight) { push.apply(args, partialRightArgs); } if (isCurry && args.length < arity) { - bitmask |= 16 & ~32 + bitmask |= 16 & ~32; return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); } if (isBindKey) { @@ -1515,13 +1538,7 @@ return func.apply(thisBinding, args); }; } - // take a snapshot of `arguments` before juggling - bindData = nativeSlice.call(arguments); - if (isBindKey) { - var key = thisArg; - thisArg = func; - } - setBindData(bound, bindData); + setBindData(bound, nativeSlice.call(arguments)); return bound; } @@ -3341,17 +3358,25 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length != 'number') { - var props = keys(collection); - length = props.length; - } else if (support.unindexedChars && isString(collection)) { - iterable = collection.split(''); + callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); + if (isArray(collection)) { + while (length--) { + if (callback(collection[length], length, collection) === false) { + break; + } + } + } else { + if (typeof length != 'number') { + var props = keys(collection); + length = props.length; + } else if (support.unindexedChars && isString(collection)) { + iterable = collection.split(''); + } + baseEach(collection, function(value, key, collection) { + key = props ? props[--length] : --length; + return callback(iterable[key], key, collection); + }); } - callback = baseCreateCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { - index = props ? props[--length] : --length; - return callback(iterable[index], index, collection); - }); return collection; } @@ -4373,7 +4398,7 @@ var index = sortedIndex(array, value); return array[index] === value ? index : -1; } - return array ? baseIndexOf(array, value, fromIndex) : -1; + return baseIndexOf(array, value, fromIndex); } /** @@ -5139,7 +5164,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = bind(object[key], object); + object[key] = createBound(object[key], 1, null, null, object); } return object; } @@ -5179,7 +5204,7 @@ * // => 'hi, moe!' */ function bindKey(object, key) { - return createBound(object, 19, nativeSlice.call(arguments, 2), null, key); + return createBound(key, 19, nativeSlice.call(arguments, 2), null, object); } /** @@ -5400,12 +5425,11 @@ var remaining = wait - (new Date - stamp); if (remaining <= 0) { var isCalled = trailing && (!leading || callCount > 1); - callCount = 0; - timeoutId = null; if (maxTimeoutId) { clearTimeout(maxTimeoutId); - maxTimeoutId = null; } + callCount = 0; + maxTimeoutId = timeoutId = null; if (isCalled) { lastCalled = +new Date; result = func.apply(thisArg, args); @@ -5416,8 +5440,10 @@ }; var maxDelayed = function() { + if (timeoutId) { + clearTimeout(timeoutId); + } callCount = 0; - clearTimeout(timeoutId); maxTimeoutId = timeoutId = null; if (trailing || (maxWait !== wait)) { lastCalled = +new Date;