diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 285d6fd00..5fd66c455 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -1180,6 +1180,62 @@ return bind(func, thisArg); } + /** + * The base implementation of `createWrapper` without `func` type checking + * or support for setting meta data. + * + * @private + * @param {Function|string} func The function or method name to reference. + * @param {number} bitmask The bitmask of method flags to compose. + * @param {Array} [partialArgs] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [partialRightArgs] An array of arguments to append to those + * provided to the new function. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new function. + */ + function baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + var isBind = bitmask & 1, + isBindKey = bitmask & 2, + isCurry = bitmask & 4, + isCurryBound = bitmask & 8, + isPartial = bitmask & 16, + isPartialRight = bitmask & 32, + key = func; + + function bound() { + var thisBinding = isBind ? thisArg : this; + if (isCurry || isPartial || isPartialRight) { + if (isPartial) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + if (isPartialRight || isCurry) { + args || (args = slice(arguments)); + if (isPartialRight) { + push.apply(args, partialRightArgs); + } + if (isCurry && args.length < arity) { + bitmask |= 16 & ~32; + return createWrapper(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); + } + } + } + args || (args = arguments); + if (isBindKey) { + func = thisBinding[key]; + } + if (this instanceof bound) { + thisBinding = baseCreate(func.prototype); + var result = func.apply(thisBinding, args); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisBinding, args); + } + return bound; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -1571,16 +1627,15 @@ * provided to the new function. * @param {*} [thisArg] The `this` binding of `func`. * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new bound function. + * @returns {Function} Returns the new function. */ - function createBound(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32, - key = func; + isPartialRight = bitmask & 32; if (!isBindKey && !isFunction(func)) { throw new TypeError; @@ -1619,45 +1674,15 @@ } // merge flags bindData[1] |= bitmask; - return createBound.apply(null, bindData); + return createWrapper.apply(null, bindData); } // fast path for `_.bind` - if (bitmask == 1 || bitmask === 17) { - var bound = baseBind(func, thisArg, partialArgs); - } - else { - bound = function() { - var thisBinding = isBind ? thisArg : this; - if (isCurry || isPartial || isPartialRight) { - if (isPartial) { - var args = partialArgs.slice(); - push.apply(args, arguments); - } - if (isPartialRight || isCurry) { - args || (args = slice(arguments)); - if (isPartialRight) { - push.apply(args, partialRightArgs); - } - if (isCurry && args.length < arity) { - bitmask |= 16 & ~32; - return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); - } - } - } - args || (args = arguments); - if (isBindKey) { - func = thisBinding[key]; - } - if (this instanceof bound) { - thisBinding = baseCreate(func.prototype); - var result = func.apply(thisBinding, args); - return isObject(result) ? result : thisBinding; - } - return func.apply(thisBinding, args); - }; - } - setBindData(bound, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); - return bound; + var result = (bitmask == 1 || bitmask === 17) + ? baseBind(func, thisArg, partialArgs) + : baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity); + + setBindData(result, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); + return result; } /** @@ -5354,8 +5379,8 @@ */ function bind(func, thisArg) { return arguments.length > 2 - ? createBound(func, 17, slice(arguments, 2), null, thisArg) - : createBound(func, 1, null, null, thisArg); + ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) + : createWrapper(func, 1, null, null, thisArg); } /** @@ -5389,7 +5414,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = createBound(object[key], 1, null, null, object); + object[key] = createWrapper(object[key], 1, null, null, object); } return object; } @@ -5430,8 +5455,8 @@ */ function bindKey(object, key) { return arguments.length > 2 - ? createBound(key, 19, slice(arguments, 2), null, object) - : createBound(key, 3, null, null, object); + ? createWrapper(key, 19, slice(arguments, 2), null, object) + : createWrapper(key, 3, null, null, object); } /** @@ -5582,7 +5607,7 @@ */ function curry(func, arity) { arity = typeof arity == 'number' ? arity : (+arity || func.length); - return createBound(func, 4, null, null, null, arity); + return createWrapper(func, 4, null, null, null, arity); } /** @@ -5876,7 +5901,7 @@ * // => 'hi fred' */ function partial(func) { - return createBound(func, 16, slice(arguments, 1)); + return createWrapper(func, 16, slice(arguments, 1)); } /** @@ -5907,7 +5932,7 @@ * // => { '_': _, 'jq': $ } */ function partialRight(func) { - return createBound(func, 32, null, slice(arguments, 1)); + return createWrapper(func, 32, null, slice(arguments, 1)); } /** @@ -5983,7 +6008,7 @@ * // => '

Fred, Wilma, & Pebbles

' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index a72b930cc..417fe8f75 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,54 +5,54 @@ */ ;(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=w&&f===n,h=u||g?i():c;if(g){var v=o(h);v?(f=t,h=v):(g=!1,h=u?h:(p(h),c))}for(;++af(h,y))&&((u||g)&&h.push(y),c.push(v))}return g?(p(h.k),s(h)):u&&p(h),c}function ct(n){return function(t,e,r){var u={};if(e=y.createCallback(e,r,3),qe(t)){r=-1;for(var o=t.length;++rk;k++)r+="n='"+e.h[k]+"';if((!(r&&x[n])&&m.call(t,n))",e.j||(r+="||(!x[n]&&t[n]!==A[n])"),r+="){"+e.g+"}"; -r+="}"}return(e.b||Te.nonEnumArgs)&&(r+="}"),r+=e.c+";return E",n("d,j,k,m,o,p,q,s,v,A,B,y,I,J,L",t+r+"}")(et,K,le,be,_,mt,qe,Ct,X.f,ce,Y,Le,H,pe,ge)}function gt(n){return He[n]}function ht(){var t=(t=y.indexOf)===zt?n:t;return t}function vt(n){var t,e;return!n||ge.call(n)!=J||(t=n.constructor,wt(t)&&!(t instanceof t))||!Te.argsClass&&mt(n)||!Te.nodeClass&&l(n)?!1:Te.ownLast?(nr(n,function(n,t,r){return e=be.call(r,t),!1}),false!==e):(nr(n,function(n,t){e=t}),typeof e=="undefined"||be.call(n,e))}function yt(n){return Ue[n] -}function mt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ge.call(n)==L||!1}function dt(n,t,e){var r=We(n),u=r.length;for(t=et(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function _t(n){var t=[];return nr(n,function(n,e){wt(n)&&t.push(e)}),t.sort()}function bt(n){for(var t=-1,e=We(n),r=e.length,u={};++te?Ne(0,o+e):e)||0,qe(n)?a=-1o&&(o=i)}}else t=null==t&&Ct(n)?r:y.createCallback(t,e,3),Xe(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Pt(n,t,e,r){var u=3>arguments.length;if(t=et(t,r,4),qe(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=et(t,r,4),Dt(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o) -}),e}function Ft(n){var t=-1,e=n?n.length:0,r=Yt(typeof e=="number"?e:0);return At(n,function(n){var e=ft(0,++t);r[t]=r[e],r[e]=n}),r}function $t(n,t,e){var r;if(t=y.createCallback(t,e,3),qe(n)){e=-1;for(var u=n.length;++e=w&&u===n;if(l){var c=o(i);c?(u=t,i=c):l=!1}for(;++ru(i,c)&&f.push(c);return l&&s(i),f}function Tt(n,t,e){var r=0,u=n?n.length:0; -if(typeof t!="number"&&null!=t){var o=-1;for(t=y.createCallback(t,e,3);++or?Ne(0,u+r):r||0}else if(r)return r=Kt(t,e),t[r]===e?r:-1;return n(t,e,r)}function qt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=y.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:D,variable:"",imports:{_:y}},Oe||(tt=function(n){if(jt(n)){c.prototype=n;var t=new c;c.prototype=null}return t||{}});var ze=Ee?function(n,t){Q.value=t,Ee(n,"__bindData__",Q)}:c;Te.argsClass||(mt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&be.call(n,"callee")||!1});var qe=Se||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ge.call(n)==T||!1 -},Ke=st({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),We=De?function(n){return jt(n)?Te.enumPrototypes&&typeof n=="function"||Te.nonEnumArgs&&n.length&&mt(n)?Ke(n):De(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=bt(He),Ve=oe("("+We(Ue).join("|")+")","g"),Qe=oe("["+We(He).join("")+"]","g"),Xe=st(Ge),Ye=st(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=st(Je),nr=st(Ge,Me,{j:!1}),tr=st(Ge,Me); -wt(/x/)&&(wt=function(n){return typeof n=="function"&&ge.call(n)==W});var er=_e?function(n){if(!n||ge.call(n)!=J||!Te.argsClass&&mt(n))return!1;var t=n.valueOf,e=typeof t=="function"&&(e=_e(t))&&_e(e);return e?n==e||_e(n)==e:vt(n)}:vt,rr=ct(function(n,t,e){be.call(n,e)?n[e]++:n[e]=1}),ur=ct(function(n,t,e){(be.call(n,e)?n[e]:n[e]=[]).push(t)}),or=ct(function(n,t,e){n[e]=t}),ar=Nt;Fe&&(Ut=function(n){if(!wt(n))throw new ie;return Fe.apply(e,arguments)});var ir=8==Pe(x+"08")?Pe:function(n,t){return Pe(Ct(n)?n.replace(N,""):n,t||0) -};return y.after=function(n,t){if(!wt(t))throw new ie;return function(){return 1>--n?t.apply(this,arguments):void 0}},y.assign=Ye,y.at=function(n){var t=arguments,e=-1,r=ut(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Yt(t);for(Te.unindexedChars&&Ct(n)&&(n=n.split(""));++e=w&&o(a?r[a]:v)}n:for(;++l(m?t(m,y):c(v,y))){for(a=u,(m||v).push(y);--a;)if(m=f[a],0>(m?t(m,y):c(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&s(m);return p(f),p(v),h},y.invert=bt,y.invoke=function(n,t){var e=g(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Yt(typeof o=="number"?o:0);return At(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},y.keys=We,y.map=Nt,y.max=Bt,y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0]; -return be.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!wt(n))throw new ie;return e.cache={},e},y.merge=function(n){var t=arguments,e=2;if(!jt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(a,e))&&(o[e]=n)}),o},y.once=function(n){var t,e;if(!wt(n))throw new ie;return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},y.pairs=function(n){for(var t=-1,e=We(n),r=e.length,u=Yt(r);++te?Ne(0,r+e):Be(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},y.mixin=Qt,y.noConflict=function(){return e._=se,this},y.parseInt=ir,y.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=!0)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Re(),Be(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):ft(n,t) -},y.reduce=Pt,y.reduceRight=Rt,y.result=function(n,t){if(n){var e=n[t];return wt(e)?n[t]():e}},y.runInContext=h,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:We(n).length},y.some=$t,y.sortedIndex=Kt,y.template=function(n,t,e){var r=y.templateSettings;n=ae(n||""),e=Ze({},e,r);var u,o=Ze({},e.imports,r.imports),r=We(o),o=kt(o),i=0,f=e.interpolate||B,l="__p+='",f=oe((e.escape||B).source+"|"+f.source+"|"+(f===D?S:B).source+"|"+(e.evaluate||B).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(i,c).replace(R,a),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t -}),l+="';",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(C,""):l).replace(E,"$1").replace(O,"$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=te(r,"return "+l).apply(v,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},y.unescape=function(n){return null==n?"":ae(n).replace(Ve,yt)},y.uniqueId=function(n){var t=++d;return ae(null==n?"":n)+t -},y.all=Ot,y.any=$t,y.detect=It,y.findWhere=It,y.foldl=Pt,y.foldr=Rt,y.include=Et,y.inject=Pt,tr(y,function(n,t){y.prototype[t]||(y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return je.apply(t,arguments),t=n.apply(y,t),e?new m(t,e):t})}),y.first=Tt,y.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=y.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:v;return g(n,Ne(0,u-r))},y.sample=function(n,t,e){return n&&typeof n.length!="number"?n=kt(n):Te.unindexedChars&&Ct(n)&&(n=n.split("")),null==t||e?n?n[ft(0,n.length-1)]:v:(n=Ft(n),n.length=Be(Ne(0,t),n.length),n) -},y.take=Tt,y.head=Tt,tr(y,function(n,t){var e="sample"!==t;y.prototype[t]||(y.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new m(o,u):o})}),y.VERSION="2.2.1",y.prototype.chain=function(){return this.__chain__=!0,this},y.prototype.toString=function(){return ae(this.__wrapped__)},y.prototype.value=Xt,y.prototype.valueOf=Xt,Xe(["join","pop","shift"],function(n){var t=fe[n];y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); -return n?new m(e,n):e}}),Xe(["push","reverse","sort","unshift"],function(n){var t=fe[n];y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Xe(["concat","slice","splice"],function(n){var t=fe[n];y.prototype[n]=function(){return new m(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Te.spliceObjects||Xe(["pop","shift","splice"],function(n){var t=fe[n],e="splice"==n;y.prototype[n]=function(){var n=this.__chain__,r=this.__wrapped__,u=t.apply(r,arguments);return 0===r.length&&delete r[0],n||e?new m(u,n):u +}function l(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function c(){}function p(n){n.length=0,y.lengthe?0:e);++r=w&&f===n,h=u||g?i():c; +if(g){var v=o(h);v?(f=t,h=v):(g=!1,h=u?h:(p(h),c))}for(;++af(h,y))&&((u||g)&&h.push(y),c.push(v))}return g?(p(h.k),s(h)):u&&p(h),c}function pt(n){return function(t,e,r){var u={};if(e=y.createCallback(e,r,3),Ke(t)){r=-1;for(var o=t.length;++rk;k++)r+="n='"+e.h[k]+"';if((!(r&&x[n])&&m.call(t,n))",e.j||(r+="||(!x[n]&&t[n]!==A[n])"),r+="){"+e.g+"}";r+="}"}return(e.b||ze.nonEnumArgs)&&(r+="}"),r+=e.c+";return E",n("d,j,k,m,o,p,q,s,v,A,B,y,I,J,L",t+r+"}")(et,K,ce,we,_,dt,Ke,kt,X.f,pe,Y,Te,H,se,he) +}function ht(n){return Ue[n]}function vt(){var t=(t=y.indexOf)===qt?n:t;return t}function yt(n){var t,e;return!n||he.call(n)!=J||(t=n.constructor,jt(t)&&!(t instanceof t))||!ze.argsClass&&dt(n)||!ze.nodeClass&&l(n)?!1:ze.ownLast?(tr(n,function(n,t,r){return e=we.call(r,t),!1}),false!==e):(tr(n,function(n,t){e=t}),typeof e=="undefined"||we.call(n,e))}function mt(n){return Ve[n]}function dt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&he.call(n)==L||!1}function _t(n,t,e){var r=Ge(n),u=r.length; +for(t=et(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function bt(n){var t=[];return tr(n,function(n,e){jt(n)&&t.push(e)}),t.sort()}function wt(n){for(var t=-1,e=Ge(n),r=e.length,u={};++te?Be(0,o+e):e)||0,Ke(n)?a=-1o&&(o=i)}}else t=null==t&&kt(n)?r:y.createCallback(t,e,3),Ye(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n) +});return o}function Rt(n,t,e,r){var u=3>arguments.length;if(t=et(t,r,4),Ke(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=et(t,r,4),Nt(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function $t(n){var t=-1,e=n?n.length:0,r=Zt(typeof e=="number"?e:0);return Dt(n,function(n){var e=lt(0,++t);r[t]=r[e],r[e]=n}),r}function Lt(n,t,e){var r;if(t=y.createCallback(t,e,3),Ke(n)){e=-1; +for(var u=n.length;++e=w&&u===n;if(l){var c=o(i);c?(u=t,i=c):l=!1}for(;++ru(i,c)&&f.push(c);return l&&s(i),f}function zt(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=-1;for(t=y.createCallback(t,e,3);++or?Be(0,u+r):r||0}else if(r)return r=Wt(t,e),t[r]===e?r:-1;return n(t,e,r)}function Kt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=y.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:D,variable:"",imports:{_:y}},Se||(tt=function(n){if(xt(n)){c.prototype=n;var t=new c;c.prototype=null}return t||{}});var qe=Oe?function(n,t){Q.value=t,Oe(n,"__bindData__",Q)}:c;ze.argsClass||(dt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&we.call(n,"callee")||!1});var Ke=Ie||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&he.call(n)==T||!1 +},We=gt({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),Ge=Ne?function(n){return xt(n)?ze.enumPrototypes&&typeof n=="function"||ze.nonEnumArgs&&n.length&&dt(n)?We(n):Ne(n):[]}:We,Je={a:"g,e,K",i:"e=e&&typeof K=='undefined'?e:d(e,K,3)",b:"typeof u=='number'",v:Ge,g:"if(e(t[n],n,g)===false)return E"},Me={a:"z,H,l",i:"var a=arguments,b=0,c=typeof l=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Ve=wt(Ue),Qe=ae("("+Ge(Ve).join("|")+")","g"),Xe=ae("["+Ge(Ue).join("")+"]","g"),Ye=gt(Je),Ze=gt(Me,{i:Me.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]"}),nr=gt(Me),tr=gt(Je,He,{j:!1}),er=gt(Je,He); +jt(/x/)&&(jt=function(n){return typeof n=="function"&&he.call(n)==W});var rr=be?function(n){if(!n||he.call(n)!=J||!ze.argsClass&&dt(n))return!1;var t=n.valueOf,e=typeof t=="function"&&(e=be(t))&&be(e);return e?n==e||be(n)==e:yt(n)}:yt,ur=pt(function(n,t,e){we.call(n,e)?n[e]++:n[e]=1}),or=pt(function(n,t,e){(we.call(n,e)?n[e]:n[e]=[]).push(t)}),ar=pt(function(n,t,e){n[e]=t}),ir=Bt;$e&&(Vt=function(n){if(!jt(n))throw new fe;return $e.apply(e,arguments)});var fr=8==Re(x+"08")?Re:function(n,t){return Re(kt(n)?n.replace(N,""):n,t||0) +};return y.after=function(n,t){if(!jt(t))throw new fe;return function(){return 1>--n?t.apply(this,arguments):void 0}},y.assign=Ze,y.at=function(n){var t=arguments,e=-1,r=at(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Zt(t);for(ze.unindexedChars&&kt(n)&&(n=n.split(""));++e=w&&o(a?r[a]:v)}n:for(;++l(m?t(m,y):c(v,y))){for(a=u,(m||v).push(y);--a;)if(m=f[a],0>(m?t(m,y):c(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&s(m);return p(f),p(v),h},y.invert=wt,y.invoke=function(n,t){var e=g(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Zt(typeof o=="number"?o:0);return Dt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},y.keys=Ge,y.map=Bt,y.max=Pt,y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0]; +return we.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!jt(n))throw new fe;return e.cache={},e},y.merge=function(n){var t=arguments,e=2;if(!xt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(a,e))&&(o[e]=n)}),o},y.once=function(n){var t,e;if(!jt(n))throw new fe;return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},y.pairs=function(n){for(var t=-1,e=Ge(n),r=e.length,u=Zt(r);++te?Be(0,r+e):Pe(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},y.mixin=Xt,y.noConflict=function(){return e._=ge,this},y.parseInt=fr,y.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=!0)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Fe(),Pe(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):lt(n,t) +},y.reduce=Rt,y.reduceRight=Ft,y.result=function(n,t){if(n){var e=n[t];return jt(e)?n[t]():e}},y.runInContext=h,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Ge(n).length},y.some=Lt,y.sortedIndex=Wt,y.template=function(n,t,e){var r=y.templateSettings;n=ie(n||""),e=nr({},e,r);var u,o=nr({},e.imports,r.imports),r=Ge(o),o=Et(o),i=0,f=e.interpolate||B,l="__p+='",f=ae((e.escape||B).source+"|"+f.source+"|"+(f===D?S:B).source+"|"+(e.evaluate||B).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(i,c).replace(R,a),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t +}),l+="';",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(C,""):l).replace(E,"$1").replace(O,"$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=ee(r,"return "+l).apply(v,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},y.unescape=function(n){return null==n?"":ie(n).replace(Qe,mt)},y.uniqueId=function(n){var t=++d;return ie(null==n?"":n)+t +},y.all=St,y.any=Lt,y.detect=At,y.findWhere=At,y.foldl=Rt,y.foldr=Ft,y.include=Ot,y.inject=Rt,er(y,function(n,t){y.prototype[t]||(y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return xe.apply(t,arguments),t=n.apply(y,t),e?new m(t,e):t})}),y.first=zt,y.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=y.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:v;return g(n,Be(0,u-r))},y.sample=function(n,t,e){return n&&typeof n.length!="number"?n=Et(n):ze.unindexedChars&&kt(n)&&(n=n.split("")),null==t||e?n?n[lt(0,n.length-1)]:v:(n=$t(n),n.length=Pe(Be(0,t),n.length),n) +},y.take=zt,y.head=zt,er(y,function(n,t){var e="sample"!==t;y.prototype[t]||(y.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new m(o,u):o})}),y.VERSION="2.2.1",y.prototype.chain=function(){return this.__chain__=!0,this},y.prototype.toString=function(){return ie(this.__wrapped__)},y.prototype.value=Yt,y.prototype.valueOf=Yt,Ye(["join","pop","shift"],function(n){var t=le[n];y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); +return n?new m(e,n):e}}),Ye(["push","reverse","sort","unshift"],function(n){var t=le[n];y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ye(["concat","slice","splice"],function(n){var t=le[n];y.prototype[n]=function(){return new m(t.apply(this.__wrapped__,arguments),this.__chain__)}}),ze.spliceObjects||Ye(["pop","shift","splice"],function(n){var t=le[n],e="splice"==n;y.prototype[n]=function(){var n=this.__chain__,r=this.__wrapped__,u=t.apply(r,arguments);return 0===r.length&&delete r[0],n||e?new m(u,n):u }}),y}var v,y=[],m=[],d=0,_={},b=+new Date+"",w=75,j=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,E=/\b(__p\+=)''\+/g,O=/(__e\(.*?\)|\b__t\))\+'';/g,S=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,I=/\w*$/,A=/^function[ \n\r\t]+\w/,D=/<%=([\s\S]+?)%>/g,N=RegExp("^["+x+"]*0+(?=.$)"),B=/($^)/,P=/\bthis\b/,R=/['\n\r\t\u2028\u2029\\]/g,F="Array Boolean Date Error Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),$="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),L="[object Arguments]",T="[object Array]",z="[object Boolean]",q="[object Date]",K="[object Error]",W="[object Function]",G="[object Number]",J="[object Object]",M="[object RegExp]",H="[object String]",U={}; U[W]=!1,U[L]=U[T]=U[z]=U[q]=U[G]=U[J]=U[M]=U[H]=!0;var V={leading:!1,maxWait:0,trailing:!1},Q={configurable:!1,enumerable:!1,value:null,writable:!1},X={a:"",b:null,c:"",d:"",e:"",v:null,g:"",h:null,support:null,i:"",j:!1},Y={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},Z={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},nt=Y[typeof window]&&window||this,tt=Y[typeof exports]&&exports&&!exports.nodeType&&exports,et=Y[typeof module]&&module&&!module.nodeType&&module,rt=et&&et.exports===tt&&tt,ut=Y[typeof global]&&global; !ut||ut.global!==ut&&ut.window!==ut||(nt=ut);var ot=h();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(nt._=ot, define(function(){return ot})):tt&&et?rt?(et.exports=ot)._=ot:tt._=ot:nt._=ot}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 3d8b2f525..7bfbe686e 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -904,6 +904,62 @@ return bind(func, thisArg); } + /** + * The base implementation of `createWrapper` without `func` type checking + * or support for setting meta data. + * + * @private + * @param {Function|string} func The function or method name to reference. + * @param {number} bitmask The bitmask of method flags to compose. + * @param {Array} [partialArgs] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [partialRightArgs] An array of arguments to append to those + * provided to the new function. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new function. + */ + function baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + var isBind = bitmask & 1, + isBindKey = bitmask & 2, + isCurry = bitmask & 4, + isCurryBound = bitmask & 8, + isPartial = bitmask & 16, + isPartialRight = bitmask & 32, + key = func; + + function bound() { + var thisBinding = isBind ? thisArg : this; + if (isCurry || isPartial || isPartialRight) { + if (isPartial) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + if (isPartialRight || isCurry) { + args || (args = slice(arguments)); + if (isPartialRight) { + push.apply(args, partialRightArgs); + } + if (isCurry && args.length < arity) { + bitmask |= 16 & ~32; + return createWrapper(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); + } + } + } + args || (args = arguments); + if (isBindKey) { + func = thisBinding[key]; + } + if (this instanceof bound) { + thisBinding = baseCreate(func.prototype); + var result = func.apply(thisBinding, args); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisBinding, args); + } + return bound; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -1295,16 +1351,15 @@ * provided to the new function. * @param {*} [thisArg] The `this` binding of `func`. * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new bound function. + * @returns {Function} Returns the new function. */ - function createBound(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32, - key = func; + isPartialRight = bitmask & 32; if (!isBindKey && !isFunction(func)) { throw new TypeError; @@ -1343,45 +1398,15 @@ } // merge flags bindData[1] |= bitmask; - return createBound.apply(null, bindData); + return createWrapper.apply(null, bindData); } // fast path for `_.bind` - if (bitmask == 1 || bitmask === 17) { - var bound = baseBind(func, thisArg, partialArgs); - } - else { - bound = function() { - var thisBinding = isBind ? thisArg : this; - if (isCurry || isPartial || isPartialRight) { - if (isPartial) { - var args = partialArgs.slice(); - push.apply(args, arguments); - } - if (isPartialRight || isCurry) { - args || (args = slice(arguments)); - if (isPartialRight) { - push.apply(args, partialRightArgs); - } - if (isCurry && args.length < arity) { - bitmask |= 16 & ~32; - return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); - } - } - } - args || (args = arguments); - if (isBindKey) { - func = thisBinding[key]; - } - if (this instanceof bound) { - thisBinding = baseCreate(func.prototype); - var result = func.apply(thisBinding, args); - return isObject(result) ? result : thisBinding; - } - return func.apply(thisBinding, args); - }; - } - setBindData(bound, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); - return bound; + var result = (bitmask == 1 || bitmask === 17) + ? baseBind(func, thisArg, partialArgs) + : baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity); + + setBindData(result, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); + return result; } /** @@ -5015,8 +5040,8 @@ */ function bind(func, thisArg) { return arguments.length > 2 - ? createBound(func, 17, slice(arguments, 2), null, thisArg) - : createBound(func, 1, null, null, thisArg); + ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) + : createWrapper(func, 1, null, null, thisArg); } /** @@ -5050,7 +5075,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = createBound(object[key], 1, null, null, object); + object[key] = createWrapper(object[key], 1, null, null, object); } return object; } @@ -5091,8 +5116,8 @@ */ function bindKey(object, key) { return arguments.length > 2 - ? createBound(key, 19, slice(arguments, 2), null, object) - : createBound(key, 3, null, null, object); + ? createWrapper(key, 19, slice(arguments, 2), null, object) + : createWrapper(key, 3, null, null, object); } /** @@ -5243,7 +5268,7 @@ */ function curry(func, arity) { arity = typeof arity == 'number' ? arity : (+arity || func.length); - return createBound(func, 4, null, null, null, arity); + return createWrapper(func, 4, null, null, null, arity); } /** @@ -5537,7 +5562,7 @@ * // => 'hi fred' */ function partial(func) { - return createBound(func, 16, slice(arguments, 1)); + return createWrapper(func, 16, slice(arguments, 1)); } /** @@ -5568,7 +5593,7 @@ * // => { '_': _, 'jq': $ } */ function partialRight(func) { - return createBound(func, 32, null, slice(arguments, 1)); + return createWrapper(func, 32, null, slice(arguments, 1)); } /** @@ -5644,7 +5669,7 @@ * // => '

Fred, Wilma, & Pebbles

' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ diff --git a/dist/lodash.min.js b/dist/lodash.min.js index e5530de38..b93ef8723 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,50 +5,50 @@ */ ;(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=b&&f===n,h=u||v?a():s; -if(v){var g=o(h);g?(f=t,h=g):(v=!1,h=u?h:(c(h),s))}for(;++if(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.k),p(h)):u&&c(h),s}function ct(n){return function(t,e,r){var u={};e=Y.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Ee(0,o+e):e)||0,Be(n)?i=-1o&&(o=a)}}else t=null==t&&kt(n)?r:Y.createCallback(t,e,3),Et(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)}); -return o}function Dt(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Yt(r);++earguments.length;t=ut(t,r,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(e=n[++o]);++oarguments.length;return t=ut(t,r,4),St(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function Tt(n){var t=-1,e=n?n.length:0,r=Yt(typeof e=="number"?e:0); -return Et(n,function(n){var e=ft(0,++t);r[t]=r[e],r[e]=n}),r}function Bt(n,t,e){var r;t=Y.createCallback(t,e,3),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++e=b&&u===n;if(l){var c=o(a);c?(u=t,a=c):l=!1}for(;++ru(a,c)&&f.push(c);return l&&p(a),f}function qt(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=-1; -for(t=Y.createCallback(t,e,3);++or?Ee(0,u+r):r||0}else if(r)return r=Kt(t,e),t[r]===e?r:-1;return n(t,e,r)}function Pt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=Y.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:Y}},xe||(rt=function(n){if(wt(n)){l.prototype=n; -var t=new l;l.prototype=null}return t||{}});var Te=ke?function(n,t){U.value=t,ke(n,"__bindData__",U)}:l,Be=Ce||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&pe.call(n)==F||!1},We=Ne?function(n){return wt(n)?Ne(n):[]}:Q,qe={"&":"&","<":"<",">":">",'"':""","'":"'"},ze=bt(qe),Pe=oe("("+We(ze).join("|")+")","g"),Ke=oe("["+We(qe).join("")+"]","g"),Le=ct(function(n,t,e){_e.call(n,e)?n[e]++:n[e]=1}),Me=ct(function(n,t,e){(_e.call(n,e)?n[e]:n[e]=[]).push(t)}),Ue=ct(function(n,t,e){n[e]=t -});De&&(Ht=function(n){if(!dt(n))throw new ae;return De.apply(e,arguments)});var Ve=8==Re(w+"08")?Re:function(n,t){return Re(kt(n)?n.replace(E,""):n,t||0)};return Y.after=function(n,t){if(!dt(t))throw new ae;return function(){return 1>--n?t.apply(this,arguments):void 0}},Y.assign=J,Y.at=function(n){for(var t=arguments,e=-1,r=ot(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Yt(t);++e=b&&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},Y.invert=bt,Y.invoke=function(n,t){var e=s(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,i=Yt(typeof o=="number"?o:0); -return Et(n,function(n){i[++r]=(u?t:n[t]).apply(n,e)}),i},Y.keys=We,Y.map=Rt,Y.max=At,Y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0];return _e.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!dt(n))throw new ae;return e.cache={},e},Y.merge=function(n){var t=arguments,e=2;if(!wt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(i,e))&&(o[e]=n)}),o},Y.once=function(n){var t,e;if(!dt(n))throw new ae; -return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},Y.pairs=function(n){for(var t=-1,e=We(n),r=e.length,u=Yt(r);++te?Ee(0,r+e):Se(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},Y.mixin=Qt,Y.noConflict=function(){return e._=ce,this},Y.parseInt=Ve,Y.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=!0)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Ae(),Se(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):ft(n,t) -},Y.reduce=$t,Y.reduceRight=Ft,Y.result=function(n,t){if(n){var e=n[t];return dt(e)?n[t]():e}},Y.runInContext=v,Y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:We(n).length},Y.some=Bt,Y.sortedIndex=Kt,Y.template=function(n,t,e){var r=Y.templateSettings;n=ie(n||""),e=G({},e,r);var u,o=G({},e.imports,r.imports),r=We(o),o=xt(o),a=0,f=e.interpolate||S,l="__p+='",f=oe((e.escape||S).source+"|"+f.source+"|"+(f===N?C:S).source+"|"+(e.evaluate||S).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(a,c).replace(A,i),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),a=c+t.length,t -}),l+="';",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(j,""):l).replace(k,"$1").replace(x,"$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=te(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Y.unescape=function(n){return null==n?"":ie(n).replace(Pe,gt)},Y.uniqueId=function(n){var t=++m;return ie(null==n?"":n)+t -},Y.all=Ot,Y.any=Bt,Y.detect=Nt,Y.findWhere=Nt,Y.foldl=$t,Y.foldr=Ft,Y.include=Ct,Y.inject=$t,y(Y,function(n,t){Y.prototype[t]||(Y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return de.apply(t,arguments),t=n.apply(Y,t),e?new nt(t,e):t})}),Y.first=qt,Y.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=Y.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:h;return s(n,Ee(0,u-r))},Y.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=xt(n)),null==t||e?n?n[ft(0,n.length-1)]:h:(n=Tt(n),n.length=Se(Ee(0,t),n.length),n) -},Y.take=qt,Y.head=qt,y(Y,function(n,t){var e="sample"!==t;Y.prototype[t]||(Y.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new nt(o,u):o})}),Y.VERSION="2.2.1",Y.prototype.chain=function(){return this.__chain__=!0,this},Y.prototype.toString=function(){return ie(this.__wrapped__)},Y.prototype.value=Xt,Y.prototype.valueOf=Xt,Et(["join","pop","shift"],function(n){var t=fe[n];Y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); -return n?new nt(e,n):e}}),Et(["push","reverse","sort","unshift"],function(n){var t=fe[n];Y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Et(["concat","slice","splice"],function(n){var t=fe[n];Y.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Y}var h,g=[],y=[],m=0,_=+new Date+"",b=75,d=40,w=" \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",j=/\b__p\+='';/g,k=/\b(__p\+=)''\+/g,x=/(__e\(.*?\)|\b__t\))\+'';/g,C=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,O=/\w*$/,I=/^function[ \n\r\t]+\w/,N=/<%=([\s\S]+?)%>/g,E=RegExp("^["+w+"]*0+(?=.$)"),S=/($^)/,R=/\bthis\b/,A=/['\n\r\t\u2028\u2029\\]/g,D="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),$="[object Arguments]",F="[object Array]",T="[object Boolean]",B="[object Date]",W="[object Function]",q="[object Number]",z="[object Object]",P="[object RegExp]",K="[object String]",L={}; +}function l(){}function c(n){n.length=0,g.lengthe?0:e);++r=b&&f===n,h=u||v?a():s;if(v){var g=o(h);g?(f=t,h=g):(v=!1,h=u?h:(c(h),s))}for(;++if(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.k),p(h)):u&&c(h),s}function pt(n){return function(t,e,r){var u={};e=Y.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Se(0,o+e):e)||0,We(n)?i=-1o&&(o=a)}}else t=null==t&&xt(n)?r:Y.createCallback(t,e,3),St(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function $t(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Zt(r);++earguments.length;t=ut(t,r,4); +var o=-1,i=n.length;if(typeof i=="number")for(u&&(e=n[++o]);++oarguments.length;return t=ut(t,r,4),Rt(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function Bt(n){var t=-1,e=n?n.length:0,r=Zt(typeof e=="number"?e:0);return St(n,function(n){var e=lt(0,++t);r[t]=r[e],r[e]=n}),r}function Wt(n,t,e){var r;t=Y.createCallback(t,e,3),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++e=b&&u===n;if(l){var c=o(a);c?(u=t,a=c):l=!1}for(;++ru(a,c)&&f.push(c);return l&&p(a),f}function zt(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=-1;for(t=Y.createCallback(t,e,3);++or?Se(0,u+r):r||0}else if(r)return r=Lt(t,e),t[r]===e?r:-1; +return n(t,e,r)}function Kt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=Y.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:Y}},Ce||(rt=function(n){if(jt(n)){l.prototype=n;var t=new l;l.prototype=null}return t||{}});var Be=xe?function(n,t){U.value=t,xe(n,"__bindData__",U)}:l,We=Oe||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&se.call(n)==F||!1},qe=Ee?function(n){return jt(n)?Ee(n):[]}:Q,ze={"&":"&","<":"<",">":">",'"':""","'":"'"},Pe=dt(ze),Ke=ie("("+qe(Pe).join("|")+")","g"),Le=ie("["+qe(ze).join("")+"]","g"),Me=pt(function(n,t,e){be.call(n,e)?n[e]++:n[e]=1 +}),Ue=pt(function(n,t,e){(be.call(n,e)?n[e]:n[e]=[]).push(t)}),Ve=pt(function(n,t,e){n[e]=t});$e&&(Jt=function(n){if(!wt(n))throw new fe;return $e.apply(e,arguments)});var Ge=8==Ae(w+"08")?Ae:function(n,t){return Ae(xt(n)?n.replace(E,""):n,t||0)};return Y.after=function(n,t){if(!wt(t))throw new fe;return function(){return 1>--n?t.apply(this,arguments):void 0}},Y.assign=J,Y.at=function(n){for(var t=arguments,e=-1,r=it(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Zt(t);++e=b&&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},Y.invert=dt,Y.invoke=function(n,t){var e=s(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,i=Zt(typeof o=="number"?o:0);return St(n,function(n){i[++r]=(u?t:n[t]).apply(n,e)}),i},Y.keys=qe,Y.map=At,Y.max=Dt,Y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0];return be.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!wt(n))throw new fe;return e.cache={},e},Y.merge=function(n){var t=arguments,e=2; +if(!jt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(i,e))&&(o[e]=n)}),o},Y.once=function(n){var t,e;if(!wt(n))throw new fe;return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},Y.pairs=function(n){for(var t=-1,e=qe(n),r=e.length,u=Zt(r);++te?Se(0,r+e):Re(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},Y.mixin=Xt,Y.noConflict=function(){return e._=pe,this},Y.parseInt=Ge,Y.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=!0)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=De(),Re(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):lt(n,t) +},Y.reduce=Ft,Y.reduceRight=Tt,Y.result=function(n,t){if(n){var e=n[t];return wt(e)?n[t]():e}},Y.runInContext=v,Y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qe(n).length},Y.some=Wt,Y.sortedIndex=Lt,Y.template=function(n,t,e){var r=Y.templateSettings;n=ae(n||""),e=G({},e,r);var u,o=G({},e.imports,r.imports),r=qe(o),o=Ct(o),a=0,f=e.interpolate||S,l="__p+='",f=ie((e.escape||S).source+"|"+f.source+"|"+(f===N?C:S).source+"|"+(e.evaluate||S).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(a,c).replace(A,i),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),a=c+t.length,t +}),l+="';",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(j,""):l).replace(k,"$1").replace(x,"$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=ee(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Y.unescape=function(n){return null==n?"":ae(n).replace(Ke,yt)},Y.uniqueId=function(n){var t=++m;return ae(null==n?"":n)+t +},Y.all=It,Y.any=Wt,Y.detect=Et,Y.findWhere=Et,Y.foldl=Ft,Y.foldr=Tt,Y.include=Ot,Y.inject=Ft,y(Y,function(n,t){Y.prototype[t]||(Y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return we.apply(t,arguments),t=n.apply(Y,t),e?new nt(t,e):t})}),Y.first=zt,Y.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=Y.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:h;return s(n,Se(0,u-r))},Y.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=Ct(n)),null==t||e?n?n[lt(0,n.length-1)]:h:(n=Bt(n),n.length=Re(Se(0,t),n.length),n) +},Y.take=zt,Y.head=zt,y(Y,function(n,t){var e="sample"!==t;Y.prototype[t]||(Y.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new nt(o,u):o})}),Y.VERSION="2.2.1",Y.prototype.chain=function(){return this.__chain__=!0,this},Y.prototype.toString=function(){return ae(this.__wrapped__)},Y.prototype.value=Yt,Y.prototype.valueOf=Yt,St(["join","pop","shift"],function(n){var t=le[n];Y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); +return n?new nt(e,n):e}}),St(["push","reverse","sort","unshift"],function(n){var t=le[n];Y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),St(["concat","slice","splice"],function(n){var t=le[n];Y.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Y}var h,g=[],y=[],m=0,_=+new Date+"",b=75,d=40,w=" \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",j=/\b__p\+='';/g,k=/\b(__p\+=)''\+/g,x=/(__e\(.*?\)|\b__t\))\+'';/g,C=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,O=/\w*$/,I=/^function[ \n\r\t]+\w/,N=/<%=([\s\S]+?)%>/g,E=RegExp("^["+w+"]*0+(?=.$)"),S=/($^)/,R=/\bthis\b/,A=/['\n\r\t\u2028\u2029\\]/g,D="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),$="[object Arguments]",F="[object Array]",T="[object Boolean]",B="[object Date]",W="[object Function]",q="[object Number]",z="[object Object]",P="[object RegExp]",K="[object String]",L={}; L[W]=!1,L[$]=L[F]=L[T]=L[B]=L[q]=L[z]=L[P]=L[K]=!0;var M={leading:!1,maxWait:0,trailing:!1},U={configurable:!1,enumerable:!1,value:null,writable:!1},V={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},G={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},H=V[typeof window]&&window||this,J=V[typeof exports]&&exports&&!exports.nodeType&&exports,Q=V[typeof module]&&module&&!module.nodeType&&module,X=Q&&Q.exports===J&&J,Y=V[typeof global]&&global;!Y||Y.global!==Y&&Y.window!==Y||(H=Y); var Z=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(H._=Z, define(function(){return Z})):J&&Q?X?(Q.exports=Z)._=Z:J._=Z:H._=Z}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 6648cc9b1..3f554d3f4 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -476,6 +476,62 @@ return bind(func, thisArg); } + /** + * The base implementation of `createWrapper` without `func` type checking + * or support for setting meta data. + * + * @private + * @param {Function|string} func The function or method name to reference. + * @param {number} bitmask The bitmask of method flags to compose. + * @param {Array} [partialArgs] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [partialRightArgs] An array of arguments to append to those + * provided to the new function. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new function. + */ + function baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + var isBind = bitmask & 1, + isBindKey = bitmask & 2, + isCurry = bitmask & 4, + isCurryBound = bitmask & 8, + isPartial = bitmask & 16, + isPartialRight = bitmask & 32, + key = func; + + function bound() { + var thisBinding = isBind ? thisArg : this; + if (isCurry || isPartial || isPartialRight) { + if (isPartial) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + if (isPartialRight || isCurry) { + args || (args = slice(arguments)); + if (isPartialRight) { + push.apply(args, partialRightArgs); + } + if (isCurry && args.length < arity) { + bitmask |= 16 & ~32; + return createWrapper(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); + } + } + } + args || (args = arguments); + if (isBindKey) { + func = thisBinding[key]; + } + if (this instanceof bound) { + thisBinding = baseCreate(func.prototype); + var result = func.apply(thisBinding, args); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisBinding, args); + } + return bound; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -726,16 +782,15 @@ * provided to the new function. * @param {*} [thisArg] The `this` binding of `func`. * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new bound function. + * @returns {Function} Returns the new function. */ - function createBound(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32, - key = func; + isPartialRight = bitmask & 32; if (!isBindKey && !isFunction(func)) { throw new TypeError; @@ -749,41 +804,11 @@ isPartialRight = partialRightArgs = false; } // fast path for `_.bind` - if (bitmask == 1 || bitmask === 17) { - var bound = baseBind(func, thisArg, partialArgs); - } - else { - bound = function() { - var thisBinding = isBind ? thisArg : this; - if (isCurry || isPartial || isPartialRight) { - if (isPartial) { - var args = partialArgs.slice(); - push.apply(args, arguments); - } - if (isPartialRight || isCurry) { - args || (args = slice(arguments)); - if (isPartialRight) { - push.apply(args, partialRightArgs); - } - if (isCurry && args.length < arity) { - bitmask |= 16 & ~32; - return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); - } - } - } - args || (args = arguments); - if (isBindKey) { - func = thisBinding[key]; - } - if (this instanceof bound) { - thisBinding = baseCreate(func.prototype); - var result = func.apply(thisBinding, args); - return isObject(result) ? result : thisBinding; - } - return func.apply(thisBinding, args); - }; - } - return bound; + var result = (bitmask == 1 || bitmask === 17) + ? baseBind(func, thisArg, partialArgs) + : baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity); + + return result; } /** @@ -3630,8 +3655,8 @@ */ function bind(func, thisArg) { return arguments.length > 2 - ? createBound(func, 17, slice(arguments, 2), null, thisArg) - : createBound(func, 1, null, null, thisArg); + ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) + : createWrapper(func, 1, null, null, thisArg); } /** @@ -3665,7 +3690,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = createBound(object[key], 1, null, null, object); + object[key] = createWrapper(object[key], 1, null, null, object); } return object; } @@ -4052,7 +4077,7 @@ * // => 'hi fred' */ function partial(func) { - return createBound(func, 16, slice(arguments, 1)); + return createWrapper(func, 16, slice(arguments, 1)); } /** @@ -4129,7 +4154,7 @@ * // => '

Fred, Wilma, & Pebbles

' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 4600a16db..4e4669411 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,37 +3,37 @@ * Lo-Dash 2.2.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * 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(tt?0:t);++eu(f,l))&&(t&&f.push(l),i.push(a))}return i}function g(n){return function(r,t,e){var u={};t=Q(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++eu&&(u=t);else r=null==r&&O(n)?charAtCallback:Q(r,t,3),F(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function $(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++targuments.length;r=l(r,e,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(t=n[++o]);++oarguments.length;return r=l(r,e,4),q(n,function(n,e,o){t=u?(u=!1,n):r(t,n,e,o)}),t}function z(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return F(n,function(n){var t;t=++r,t=0+Or(Ir()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function C(n,r,t){var e;r=Q(r,t,3),t=-1; -var u=n?n.length:0;if(typeof u=="number")for(;++tt(u,i)&&o.push(i)}return o}function V(n,r,t){var e=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=-1;for(r=Q(r,t,3);++ie?Mr(0,u+e):e||0}else if(e)return e=J(r,t),r[e]===t?e:-1;return n(r,t,e)}function H(n,r,t){if(typeof r!="number"&&null!=r){var e=0,o=-1,i=n?n.length:0;for(r=Q(r,t,3);++o>>1,t(n[e])/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Rr||(a=function(n){if(E(n)){e.prototype=n;var r=new e;e.prototype=null}return r||{}}),_(arguments)||(_=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Sr.call(n,"callee")||!1});var zr=Br||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ar.call(n)==fr||!1 -},Cr=function(n){var r,t=[];if(!n||!hr[typeof n])return t;for(r in n)Sr.call(n,r)&&t.push(r);return t},Pr=Dr?function(n){return E(n)?Dr(n):[]}:Cr,Ur={"&":"&","<":"<",">":">",'"':""","'":"'"},Vr=j(Ur),Gr=RegExp("("+Pr(Vr).join("|")+")","g"),Hr=RegExp("["+Pr(Ur).join("")+"]","g"),Jr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(r(n[t],t,n)===tr)break;return n},Kr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(Sr.call(n,t)&&r(n[t],t,n)===tr)break; -return n};A(/x/)&&(A=function(n){return typeof n=="function"&&"[object Function]"==Ar.call(n)});var Lr=g(function(n,r,t){Sr.call(n,t)?n[t]++:n[t]=1}),Qr=g(function(n,r,t){(Sr.call(n,t)?n[t]:n[t]=[]).push(r)}),Xr=g(function(n,r,t){n[t]=r});o.after=function(n,r){if(!A(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=L,o.bindAll=function(n){for(var r=1u(i,f)){for(var a=t;--a;)if(0>u(r[a],f))continue n; -i.push(f)}}return i},o.invert=j,o.invoke=function(n,r){var t=u(arguments,2),e=-1,o=typeof r=="function",i=n?n.length:0,f=Array(typeof i=="number"?i:0);return F(n,function(n){f[++e]=(o?r:n[r]).apply(n,t)}),f},o.keys=Pr,o.map=D,o.max=M,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):er+arguments[0];return Sr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e;typeof r!="function"&&t&&t[r]===n&&(r=null);var o=-1,i=n?n.length:0;if(null==r&&typeof i=="number")for(;++or(t,u)&&(e[u]=n)}),e},o.once=function(n){var r,t;if(!A(n))throw new TypeError;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},o.pairs=function(n){for(var r=-1,t=Pr(n),e=t.length,u=Array(e);++rr?0:r);++nt?Mr(0,e+t):$r(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=Z,o.noConflict=function(){return yr._=xr,this},o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Or(Ir()*(r-n+1))},o.reduce=I,o.reduceRight=W,o.result=function(n,r){if(n){var t=n[r];return A(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0; -return typeof r=="number"?r:Pr(n).length},o.some=C,o.sortedIndex=J,o.template=function(n,r,e){var u=o,i=u.templateSettings;n=(n||"")+"",e=b({},e,i);var f=0,a="__p+='",i=e.variable;n.replace(RegExp((e.escape||ur).source+"|"+(e.interpolate||ur).source+"|"+(e.evaluate||ur).source+"|$","g"),function(r,e,u,o,i){return a+=n.slice(f,i).replace(or,t),e&&(a+="'+_.escape("+e+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r}),a+="';",i||(i="obj",a="with("+i+"||{}){"+a+"}"),a="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; -try{var l=Function("_","return "+a)(u)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},o.unescape=function(n){return null==n?"":(n+"").replace(Gr,m)},o.uniqueId=function(n){var r=++rr+"";return n?n+r:r},o.all=N,o.any=C,o.detect=B,o.findWhere=function(n,r){return P(n,r,!0)},o.foldl=I,o.foldr=W,o.include=k,o.inject=I,o.first=V,o.last=function(n,r,t){var e=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=o;for(r=Q(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n?n[o-1]:nr; -return u(n,Mr(0,o-e))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=S(n)),null==r||t?n?n[0+Or(Ir()*(n.length-1-0+1))]:nr:(n=z(n),n.length=$r(Mr(0,r),n.length),n)},o.take=V,o.head=V,Z(o),o.VERSION="2.2.1",o.prototype.chain=function(){return this.__chain__=!0,this},o.prototype.value=function(){return this.__wrapped__},F("pop push reverse shift sort splice unshift".split(" "),function(n){var r=wr[n];o.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),Wr.spliceObjects||0!==n.length||delete n[0],this -}}),F(["concat","join","slice"],function(n){var r=wr[n];o.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?(yr._=o, define(function(){return o})):mr&&_r?dr?(_r.exports=o)._=o:mr._=o:yr._=o}).call(this); \ No newline at end of file +;(function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined")return 1;if(tt?0:t);++eu(f,l))&&(t&&f.push(l),i.push(a))}return i}function h(n){return function(r,t,e){var u={};t=X(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++eu&&(u=t);else r=null==r&&S(n)?charAtCallback:X(r,t,3),q(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function I(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++targuments.length;r=l(r,e,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(t=n[++o]);++oarguments.length;return r=l(r,e,4),D(n,function(n,e,o){t=u?(u=!1,n):r(t,n,e,o)}),t}function C(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return q(n,function(n){var t;t=++r,t=0+Sr(Wr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function P(n,r,t){var e;r=X(r,t,3),t=-1; +var u=n?n.length:0;if(typeof u=="number")for(;++tt(u,i)&&o.push(i)}return o}function G(n,r,t){var e=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=-1;for(r=X(r,t,3);++ie?$r(0,u+e):e||0}else if(e)return e=K(r,t),r[e]===t?e:-1;return n(r,t,e)}function J(n,r,t){if(typeof r!="number"&&null!=r){var e=0,o=-1,i=n?n.length:0;for(r=X(r,t,3);++o>>1,t(n[e])/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Br||(a=function(n){if(T(n)){e.prototype=n;var r=new e;e.prototype=null}return r||{}}),d(arguments)||(d=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&kr.call(n,"callee")||!1});var Cr=Fr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Er.call(n)==ar||!1 +},Pr=function(n){var r,t=[];if(!n||!vr[typeof n])return t;for(r in n)kr.call(n,r)&&t.push(r);return t},Ur=Mr?function(n){return T(n)?Mr(n):[]}:Pr,Vr={"&":"&","<":"<",">":">",'"':""","'":"'"},Gr=x(Vr),Hr=RegExp("("+Ur(Gr).join("|")+")","g"),Jr=RegExp("["+Ur(Vr).join("")+"]","g"),Kr=function(n,r){var t;if(!n||!vr[typeof n])return n;for(t in n)if(r(n[t],t,n)===er)break;return n},Lr=function(n,r){var t;if(!n||!vr[typeof n])return n;for(t in n)if(kr.call(n,t)&&r(n[t],t,n)===er)break; +return n};E(/x/)&&(E=function(n){return typeof n=="function"&&"[object Function]"==Er.call(n)});var Qr=h(function(n,r,t){kr.call(n,t)?n[t]++:n[t]=1}),Xr=h(function(n,r,t){(kr.call(n,t)?n[t]:n[t]=[]).push(r)}),Yr=h(function(n,r,t){n[t]=r});o.after=function(n,r){if(!E(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=Q,o.bindAll=function(n){for(var r=1u(i,f)){for(var a=t;--a;)if(0>u(r[a],f))continue n; +i.push(f)}}return i},o.invert=x,o.invoke=function(n,r){var t=u(arguments,2),e=-1,o=typeof r=="function",i=n?n.length:0,f=Array(typeof i=="number"?i:0);return q(n,function(n){f[++e]=(o?r:n[r]).apply(n,t)}),f},o.keys=Ur,o.map=M,o.max=$,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):ur+arguments[0];return kr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e;typeof r!="function"&&t&&t[r]===n&&(r=null);var o=-1,i=n?n.length:0;if(null==r&&typeof i=="number")for(;++or(t,u)&&(e[u]=n)}),e},o.once=function(n){var r,t;if(!E(n))throw new TypeError;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},o.pairs=function(n){for(var r=-1,t=Ur(n),e=t.length,u=Array(e);++rr?0:r);++nt?$r(0,e+t):Ir(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=nr,o.noConflict=function(){return mr._=Ar,this},o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Sr(Wr()*(r-n+1))},o.reduce=W,o.reduceRight=z,o.result=function(n,r){if(n){var t=n[r];return E(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0; +return typeof r=="number"?r:Ur(n).length},o.some=P,o.sortedIndex=K,o.template=function(n,r,e){var u=o,i=u.templateSettings;n=(n||"")+"",e=w({},e,i);var f=0,a="__p+='",i=e.variable;n.replace(RegExp((e.escape||or).source+"|"+(e.interpolate||or).source+"|"+(e.evaluate||or).source+"|$","g"),function(r,e,u,o,i){return a+=n.slice(f,i).replace(ir,t),e&&(a+="'+_.escape("+e+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r}),a+="';",i||(i="obj",a="with("+i+"||{}){"+a+"}"),a="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; +try{var l=Function("_","return "+a)(u)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},o.unescape=function(n){return null==n?"":(n+"").replace(Hr,_)},o.uniqueId=function(n){var r=++tr+"";return n?n+r:r},o.all=R,o.any=P,o.detect=F,o.findWhere=function(n,r){return U(n,r,!0)},o.foldl=W,o.foldr=z,o.include=N,o.inject=W,o.first=G,o.last=function(n,r,t){var e=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=o;for(r=X(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n?n[o-1]:rr; +return u(n,$r(0,o-e))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=k(n)),null==r||t?n?n[0+Sr(Wr()*(n.length-1-0+1))]:rr:(n=C(n),n.length=Ir($r(0,r),n.length),n)},o.take=G,o.head=G,nr(o),o.VERSION="2.2.1",o.prototype.chain=function(){return this.__chain__=!0,this},o.prototype.value=function(){return this.__wrapped__},q("pop push reverse shift sort splice unshift".split(" "),function(n){var r=jr[n];o.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),zr.spliceObjects||0!==n.length||delete n[0],this +}}),q(["concat","join","slice"],function(n){var r=jr[n];o.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?(mr._=o, define(function(){return o})):_r&&dr?br?(dr.exports=o)._=o:_r._=o:mr._=o}).call(this); \ No newline at end of file diff --git a/lodash.js b/lodash.js index 47c792101..7ed6f86ca 100644 --- a/lodash.js +++ b/lodash.js @@ -528,6 +528,10 @@ splice = arrayRef.splice, unshift = arrayRef.unshift; + /** Used to detect `setImmediate` in Node.js */ + var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' && + !reNative.test(setImmediate) && setImmediate; + /** Used to set meta data */ var defineProperty = (function() { // IE 8 only accepts DOM elements @@ -550,10 +554,6 @@ nativeParseInt = context.parseInt, nativeRandom = Math.random; - /** Used to detect `setImmediate` in Node.js */ - var isV8 = nativeCreate && !/\n/.test(nativeCreate) && !reNative.test(context.attachEvent), - setImmediate = typeof (setImmediate = isV8 && moduleExports && context.setImmediate) == 'function' && setImmediate; - /** Used to lookup a built-in constructor by [[Class]] */ var ctorByClass = {}; ctorByClass[arrayClass] = Array; @@ -995,16 +995,18 @@ /*--------------------------------------------------------------------------*/ /** - * The base implementation of `_.bind` without `func` type checking or support - * for setting meta data. + * The base implementation of `_.bind` that creates the bound function and + * sets its meta data. * * @private - * @param {Function} func The function to bind. - * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partialArgs] An array of arguments to be partially applied. + * @param {Array} bindData The bind data array. * @returns {Function} Returns the new bound function. */ - function baseBind(func, thisArg, partialArgs) { + function baseBind(bindData) { + var func = bindData[0], + partialArgs = bindData[2], + thisArg = bindData[4]; + function bound() { // `Function#bind` spec // http://es5.github.io/#x15.3.4.5 @@ -1022,6 +1024,7 @@ } return func.apply(thisArg, args || arguments); } + setBindData(bound, bindData); return bound; } @@ -1197,6 +1200,61 @@ return bind(func, thisArg); } + /** + * The base implementation of `createWrapper` that creates the wrapper and + * sets its meta data. + * + * @private + * @param {Array} bindData The bind data array. + * @returns {Function} Returns the new function. + */ + function baseCreateWrapper(bindData) { + var func = bindData[0], + bitmask = bindData[1], + partialArgs = bindData[2], + partialRightArgs = bindData[3], + thisArg = bindData[4], + arity = bindData[5]; + + var isBind = bitmask & 1, + isBindKey = bitmask & 2, + isCurry = bitmask & 4, + isCurryBound = bitmask & 8, + key = func; + + function bound() { + var thisBinding = isBind ? thisArg : this; + if (isCurry || partialArgs || partialRightArgs) { + if (partialArgs) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + if (partialRightArgs || isCurry) { + args || (args = slice(arguments)); + if (partialRightArgs) { + push.apply(args, partialRightArgs); + } + if (isCurry && args.length < arity) { + bitmask |= 16 & ~32; + return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]); + } + } + } + args || (args = arguments); + if (isBindKey) { + func = thisBinding[key]; + } + if (this instanceof bound) { + thisBinding = baseCreate(func.prototype); + var result = func.apply(thisBinding, args); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisBinding, args); + } + setBindData(bound, bindData); + return bound; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -1588,16 +1646,15 @@ * provided to the new function. * @param {*} [thisArg] The `this` binding of `func`. * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new bound function. + * @returns {Function} Returns the new function. */ - function createBound(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32, - key = func; + isPartialRight = bitmask & 32; if (!isBindKey && !isFunction(func)) { throw new TypeError; @@ -1636,45 +1693,11 @@ } // merge flags bindData[1] |= bitmask; - return createBound.apply(null, bindData); + return createWrapper.apply(null, bindData); } // fast path for `_.bind` - if (bitmask == 1 || bitmask === 17) { - var bound = baseBind(func, thisArg, partialArgs); - } - else { - bound = function() { - var thisBinding = isBind ? thisArg : this; - if (isCurry || isPartial || isPartialRight) { - if (isPartial) { - var args = partialArgs.slice(); - push.apply(args, arguments); - } - if (isPartialRight || isCurry) { - args || (args = slice(arguments)); - if (isPartialRight) { - push.apply(args, partialRightArgs); - } - if (isCurry && args.length < arity) { - bitmask |= 16 & ~32; - return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); - } - } - } - args || (args = arguments); - if (isBindKey) { - func = thisBinding[key]; - } - if (this instanceof bound) { - thisBinding = baseCreate(func.prototype); - var result = func.apply(thisBinding, args); - return isObject(result) ? result : thisBinding; - } - return func.apply(thisBinding, args); - }; - } - setBindData(bound, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); - return bound; + var creater = (bitmask == 1 || bitmask === 17) ? baseBind : baseCreateWrapper; + return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); } /** @@ -1755,7 +1778,7 @@ * * @private * @param {Function} func The function to set data on. - * @param {*} value The value to set. + * @param {Array} value The data array to set. */ var setBindData = !defineProperty ? noop : function(func, value) { descriptor.value = value; @@ -5372,8 +5395,8 @@ */ function bind(func, thisArg) { return arguments.length > 2 - ? createBound(func, 17, slice(arguments, 2), null, thisArg) - : createBound(func, 1, null, null, thisArg); + ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) + : createWrapper(func, 1, null, null, thisArg); } /** @@ -5407,7 +5430,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = createBound(object[key], 1, null, null, object); + object[key] = createWrapper(object[key], 1, null, null, object); } return object; } @@ -5448,8 +5471,8 @@ */ function bindKey(object, key) { return arguments.length > 2 - ? createBound(key, 19, slice(arguments, 2), null, object) - : createBound(key, 3, null, null, object); + ? createWrapper(key, 19, slice(arguments, 2), null, object) + : createWrapper(key, 3, null, null, object); } /** @@ -5600,7 +5623,7 @@ */ function curry(func, arity) { arity = typeof arity == 'number' ? arity : (+arity || func.length); - return createBound(func, 4, null, null, null, arity); + return createWrapper(func, 4, null, null, null, arity); } /** @@ -5894,7 +5917,7 @@ * // => 'hi fred' */ function partial(func) { - return createBound(func, 16, slice(arguments, 1)); + return createWrapper(func, 16, slice(arguments, 1)); } /** @@ -5925,7 +5948,7 @@ * // => { '_': _, 'jq': $ } */ function partialRight(func) { - return createBound(func, 32, null, slice(arguments, 1)); + return createWrapper(func, 32, null, slice(arguments, 1)); } /** @@ -6001,7 +6024,7 @@ * // => '

Fred, Wilma, & Pebbles

' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/