diff --git a/build.js b/build.js index beae68458..758e64f27 100644 --- a/build.js +++ b/build.js @@ -1791,6 +1791,8 @@ * @returns {string} Returns the modified source. */ function removeEsOptimization(source) { + source = removeSupportProp(source, 'funcNames'); + // remove `__bindData__` logic and `setBindData` function calls from `createBound` source = source.replace(matchFunction(source, 'createBound'), function(match) { return match diff --git a/build/pre-compile.js b/build/pre-compile.js index 7c22f7cb4..3f5730213 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -198,6 +198,7 @@ 'methods', 'min', 'mixin', + 'name', 'noConflict', 'nodeClass', 'nonEnumArgs', diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 121312e04..6679fc0f5 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -57,6 +57,9 @@ /** Used to match regexp flags from their coerced string values */ var reFlags = /\w*$/; + /** Used to detected named functions */ + var reFuncName = /^function[ \n\r\t]+\w/; + /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -710,6 +713,14 @@ */ support.fastBind = nativeBind && !isV8; + /** + * Detect if `Function#name` is supported (all but IE). + * + * @memberOf _.support + * @type boolean + */ + support.funcNames = typeof Function.name == 'string'; + /** * Detect if own properties are iterated after inherited properties (all but IE < 9). * @@ -1049,14 +1060,20 @@ if (typeof thisArg == 'undefined') { return func; } - var bindData = !func.name || func.__bindData__; + var bindData = func.__bindData__ || (support.funcNames && !func.name); if (typeof bindData == 'undefined') { - // checks if `func` references the `this` keyword and stores the result - bindData = !reThis || reThis.test(fnToString.call(func)); - setBindData(func, bindData); + var source = reThis && fnToString.call(func); + if (!support.funcNames && source && !reFuncName.test(source)) { + bindData = true; + } + if (support.funcNames || !bindData) { + // checks if `func` references the `this` keyword and stores the result + bindData = !reThis || reThis.test(source); + setBindData(func, bindData); + } } // exit early if there are no `this` references or `func` is bound - if (bindData !== true && !(bindData && bindData[1] & 1)) { + if (bindData !== true && (bindData && bindData[1] & 1)) { return func; } switch (argCount) { diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 6dcc9e024..40f3cffeb 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -4,53 +4,53 @@ * Build: `lodash -o ./dist/lodash.compat.js` */ ;(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&&l===n,h=u||g?i():c; -if(g){var v=o(h);v?(l=t,h=v):(g=!1,h=u?h:(p(h),c))}for(;++al(h,y))&&((u||g)&&h.push(y),c.push(v))}return g?(p(h.b),s(h)):u&&p(h),c}function rt(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='"+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||Le.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(V,q,oe,ve,_,pt,qe,dt,n.f,ae,U,ze,M,ie,we)}function at(n){return yt(n)?Ce(n):{}}function it(n){return He[n]}function lt(){var t=(t=y.indexOf)===Rt?n:t;return t}function ft(n){var t,e;return!n||we.call(n)!=G||(t=n.constructor,vt(t)&&!(t instanceof t))||!Le.argsClass&&pt(n)||!Le.nodeClass&&f(n)?!1:Le.ownLast?(nr(n,function(n,t,r){return e=ve.call(r,t),!1}),false!==e):(nr(n,function(n,t){e=t -}),e===v||ve.call(n,e))}function ct(n){return Ue[n]}function pt(n){return n&&typeof n=="object"?we.call(n)==$:!1}function st(n,t,e){var r=We(n),u=r.length;for(t=V(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function gt(n){var t=[];return nr(n,function(n,e){vt(n)&&t.push(e)}),t.sort()}function ht(n){for(var t=-1,e=We(n),r=e.length,u={};++te?Ie(0,o+e):e)||0,qe(n)?a=-1o&&(o=i)}}else t=!t&&dt(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 St(n,t,e,r){var u=3>arguments.length;if(t=V(t,r,4),qe(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=V(t,r,4),Ct(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function It(n){var t=-1,e=n?n.length:0,r=Ut(typeof e=="number"?e:0); -return xt(n,function(n){var e=Mt(++t);r[t]=r[e],r[e]=n}),r}function Bt(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(f){var c=o(i);c?(u=t,i=c):f=!1}for(;++ru(i,c)&&l.push(c);return f&&s(i),l -}function Nt(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&null!=t){var o=-1;for(t=y.createCallback(t,e,3);++or?Ie(0,u+r):r||0}else if(r)return r=$t(t,e),t[r]===e?r:-1;return n(t,e,r)}function Ft(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);++ti&&(u=n.apply(a,r));else{c||g||(l=o);var e=f-(o-l);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:I,variable:"",imports:{_:y}},Ce||(at=function(n){if(yt(n)){c.prototype=n;var t=new c;c.prototype=null}return t||{}});var Te=ke?function(n,t){var e=l();e.value=t,ke(n,"__bindData__",e),s(e)}:c;Le.argsClass||(pt=function(n){return n&&typeof n=="object"?ve.call(n,"callee"):!1});var qe=Ee||function(n){return n&&typeof n=="object"?we.call(n)==z:!1 -},Ke=ot({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),We=Ae?function(n){return yt(n)?Le.enumPrototypes&&typeof n=="function"||Le.nonEnumArgs&&n.length&&pt(n)?Ke(n):Ae(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=ht(He),Ve=te("("+We(Ue).join("|")+")","g"),Qe=te("["+We(He).join("")+"]","g"),Xe=ot(Ge),Ye=ot(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=ot(Je),nr=ot(Ge,Me,{j:!1}),tr=ot(Ge,Me); -vt(/x/)&&(vt=function(n){return typeof n=="function"&&we.call(n)==K});var er=he?function(n){if(!n||we.call(n)!=G||!Le.argsClass&&pt(n))return!1;var t=n.valueOf,e=typeof t=="function"&&(e=he(t))&&he(e);return e?n==e||he(n)==e:ft(n)}:ft,rr=rt(function(n,t,e){ve.call(n,e)?n[e]++:n[e]=1}),ur=rt(function(n,t,e){(ve.call(n,e)?n[e]:n[e]=[]).push(t)}),or=rt(function(n,t,e){n[e]=t}),ar=Et;Fe&&Y&&typeof de=="function"&&(Wt=function(n){if(!vt(n))throw new re;return de.apply(e,arguments)});var ir=8==De(x+"08")?De:function(n,t){return De(dt(n)?n.replace(B,""):n,t||0) -};return y.after=function(n,t){if(!vt(t))throw new re;return function(){return 1>--n?t.apply(this,arguments):void 0}},y.assign=Ye,y.at=function(n){var t=arguments,e=-1,r=X(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Ut(t);for(Le.unindexedChars&&dt(n)&&(n=n.split(""));++e=w&&o(a?r[a]:v)}n:for(;++f(m?t(m,y):c(v,y))){for(a=u,(m||v).push(y);--a;)if(m=l[a],0>(m?t(m,y):c(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=l[u])&&s(m);return p(l),p(v),h},y.invert=ht,y.invoke=function(n,t){var e=Ne.call(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Ut(typeof o=="number"?o:0);return xt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},y.keys=We,y.map=Et,y.max=Ot,y.memoize=function(n,t){if(!vt(n))throw new re;var e=function(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0]; -return ve.call(r,u)?r[u]:r[u]=n.apply(this,arguments)};return e.cache={},e},y.merge=function(n){var t=arguments,e=2;if(!yt(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(!vt(n))throw new re;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=Ut(r);++te?Ie(0,r+e):Be(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},y.mixin=Jt,y.noConflict=function(){return e._=le,this},y.parseInt=ir,y.random=Mt,y.reduce=St,y.reduceRight=At,y.result=function(n,t){var e=n?n[t]:v;return vt(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=Bt,y.sortedIndex=$t,y.template=function(n,t,e){var r=y.templateSettings; -n||(n=""),e=Ze({},e,r);var u,o=Ze({},e.imports,r.imports),r=We(o),o=_t(o),i=0,l=e.interpolate||D,f="__p+='",l=te((e.escape||D).source+"|"+l.source+"|"+(l===I?S:D).source+"|"+(e.evaluate||D).source+"|$","g");n.replace(l,function(t,e,r,o,l,c){return r||(r=o),f+=n.slice(i,c).replace(N,a),e&&(f+="'+__e("+e+")+'"),l&&(u=!0,f+="';"+l+";__p+='"),r&&(f+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t}),f+="';\n",l=e=e.variable,l||(e="obj",f="with("+e+"){"+f+"}"),f=(u?f.replace(C,""):f).replace(E,"$1").replace(O,"$1;"),f="function("+e+"){"+(l?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}"; -try{var c=Xt(r,"return "+f).apply(v,o)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.unescape=function(n){return null==n?"":ee(n).replace(Ve,ct)},y.uniqueId=function(n){var t=++d;return ee(null==n?"":n)+t},y.all=wt,y.any=Bt,y.detect=kt,y.findWhere=kt,y.foldl=St,y.foldr=At,y.include=bt,y.inject=St,tr(y,function(n,t){y.prototype[t]||(y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return ye.apply(t,arguments),t=n.apply(y,t),e?new m(t,e):t})}),y.first=Nt,y.last=function(n,t,e){if(n){var r=0,u=n.length; -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[u-1];return g(n,Ie(0,u-r))}},y.sample=function(n,t,e){return qe(n)||(n=Dt(n)),null==t||e?n[Mt(n.length-1)]:(n=It(n),n.length=Be(Ie(0,t),n.length),n)},y.take=Nt,y.head=Nt,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="1.3.1",y.prototype.chain=function(){return this.__chain__=!0,this -},y.prototype.toString=function(){return ee(this.__wrapped__)},y.prototype.value=Ht,y.prototype.valueOf=Ht,Xe(["join","pop","shift"],function(n){var t=ue[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=ue[n];y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Xe(["concat","slice","splice"],function(n){var t=ue[n];y.prototype[n]=function(){return new m(t.apply(this.__wrapped__,arguments),this.__chain__) -}}),Le.spliceObjects||Xe(["pop","shift","splice"],function(n){var t=ue[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,A=/\w*$/,I=/<%=([\s\S]+?)%>/g,B=RegExp("^["+x+"]*0+(?=.$)"),D=/($^)/,P=(P=/\bthis\b/)&&P.test(h)&&P,N=/['\n\r\t\u2028\u2029\\]/g,R="Array Boolean Date Error Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),F="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),$="[object Arguments]",z="[object Array]",L="[object Boolean]",T="[object Date]",q="[object Error]",K="[object Function]",W="[object Number]",G="[object Object]",J="[object RegExp]",M="[object String]",H={}; -H[K]=!1,H[$]=H[z]=H[L]=H[T]=H[W]=H[G]=H[J]=H[M]=!0;var U={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},V={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Q=U[typeof window]&&window||this,X=U[typeof exports]&&exports,Y=U[typeof module]&&module&&module.exports==X&&module,Z=U[typeof global]&&global;!Z||Z.global!==Z&&Z.window!==Z||(Q=Z);var nt=h();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Q._=nt, define(function(){return nt -})):X&&!X.nodeType?Y?(Y.exports=nt)._=nt:X._=nt:Q._=nt}).call(this); \ No newline at end of file +}}function r(n){return n.charCodeAt(0)}function u(n,t){var e=n.l,r=t.l;if(e!==r){if(e>r||typeof e=="undefined")return 1;if(ee?0:e);++r=w&&l===n,h=u||g?i():c;if(g){var v=o(h);v?(l=t,h=v):(g=!1,h=u?h:(p(h),c))}for(;++al(h,y))&&((u||g)&&h.push(y),c.push(v))}return g?(p(h.b),s(h)):u&&p(h),c}function ut(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='"+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(Q,K,ae,ye,_,st,Ke,_t,n.f,ie,V,Le,H,le,je)}function it(n){return mt(n)?Ee(n):{}}function lt(n){return Ue[n]}function ft(){var t=(t=y.indexOf)===Ft?n:t;return t}function ct(n){var t,e;return!n||je.call(n)!=J||(t=n.constructor,yt(t)&&!(t instanceof t))||!Te.argsClass&&st(n)||!Te.nodeClass&&f(n)?!1:Te.ownLast?(tr(n,function(n,t,r){return e=ye.call(r,t),!1}),false!==e):(tr(n,function(n,t){e=t +}),e===v||ye.call(n,e))}function pt(n){return Ve[n]}function st(n){return n&&typeof n=="object"?je.call(n)==z:!1}function gt(n,t,e){var r=Ge(n),u=r.length;for(t=Q(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function ht(n){var t=[];return tr(n,function(n,e){yt(n)&&t.push(e)}),t.sort()}function vt(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=!t&&_t(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 At(n,t,e,r){var u=3>arguments.length;if(t=Q(t,r,4),Ke(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=Q(t,r,4),Et(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=Vt(typeof e=="number"?e:0); +return Ct(n,function(n){var e=Ht(++t);r[t]=r[e],r[e]=n}),r}function Nt(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(f){var c=o(i);c?(u=t,i=c):f=!1}for(;++ru(i,c)&&l.push(c);return f&&s(i),l +}function Rt(n,t,e){if(n){var r=0,u=n.length;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=zt(t,e),t[r]===e?r:-1;return n(t,e,r)}function $t(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);++tf&&(a=n.apply(l,o));else{s||v||(c=i);var e=p-(i-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:B,variable:"",imports:{_:y}},Ee||(it=function(n){if(mt(n)){c.prototype=n;var t=new c;c.prototype=null}return t||{}});var qe=xe?function(n,t){var e=l();e.value=t,xe(n,"__bindData__",e),s(e)}:c;Te.argsClass||(st=function(n){return n&&typeof n=="object"?ye.call(n,"callee"):!1});var Ke=Oe||function(n){return n&&typeof n=="object"?je.call(n)==L:!1 +},We=at({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),Ge=Ie?function(n){return mt(n)?Te.enumPrototypes&&typeof n=="function"||Te.nonEnumArgs&&n.length&&st(n)?We(n):Ie(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=vt(Ue),Qe=ee("("+Ge(Ve).join("|")+")","g"),Xe=ee("["+Ge(Ue).join("")+"]","g"),Ye=at(Je),Ze=at(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=at(Me),tr=at(Je,He,{j:!1}),er=at(Je,He); +yt(/x/)&&(yt=function(n){return typeof n=="function"&&je.call(n)==W});var rr=ve?function(n){if(!n||je.call(n)!=J||!Te.argsClass&&st(n))return!1;var t=n.valueOf,e=typeof t=="function"&&(e=ve(t))&&ve(e);return e?n==e||ve(n)==e:ct(n)}:ct,ur=ut(function(n,t,e){ye.call(n,e)?n[e]++:n[e]=1}),or=ut(function(n,t,e){(ye.call(n,e)?n[e]:n[e]=[]).push(t)}),ar=ut(function(n,t,e){n[e]=t}),ir=Ot;$e&&Z&&typeof _e=="function"&&(Gt=function(n){if(!yt(n))throw new ue;return _e.apply(e,arguments)});var lr=8==De(x+"08")?De:function(n,t){return De(_t(n)?n.replace(N,""):n,t||0) +};return y.after=function(n,t){if(!yt(t))throw new ue;return function(){return 1>--n?t.apply(this,arguments):void 0}},y.assign=Ze,y.at=function(n){var t=arguments,e=-1,r=Y(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Vt(t);for(Te.unindexedChars&&_t(n)&&(n=n.split(""));++e=w&&o(a?r[a]:v)}n:for(;++f(m?t(m,y):c(v,y))){for(a=u,(m||v).push(y);--a;)if(m=l[a],0>(m?t(m,y):c(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=l[u])&&s(m);return p(l),p(v),h},y.invert=vt,y.invoke=function(n,t){var e=Re.call(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Vt(typeof o=="number"?o:0);return Ct(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},y.keys=Ge,y.map=Ot,y.max=St,y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0]; +return ye.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!yt(n))throw new ue;return e.cache={},e},y.merge=function(n){var t=arguments,e=2;if(!mt(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(!yt(n))throw new ue;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=Vt(r);++te?Be(0,r+e):Ne(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},y.mixin=Mt,y.noConflict=function(){return e._=fe,this},y.parseInt=lr,y.random=Ht,y.reduce=At,y.reduceRight=It,y.result=function(n,t){var e=n?n[t]:v;return yt(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=Nt,y.sortedIndex=zt,y.template=function(n,t,e){var r=y.templateSettings; +n||(n=""),e=nr({},e,r);var u,o=nr({},e.imports,r.imports),r=Ge(o),o=bt(o),i=0,l=e.interpolate||D,f="__p+='",l=ee((e.escape||D).source+"|"+l.source+"|"+(l===B?S:D).source+"|"+(e.evaluate||D).source+"|$","g");n.replace(l,function(t,e,r,o,l,c){return r||(r=o),f+=n.slice(i,c).replace(R,a),e&&(f+="'+__e("+e+")+'"),l&&(u=!0,f+="';"+l+";__p+='"),r&&(f+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t}),f+="';\n",l=e=e.variable,l||(e="obj",f="with("+e+"){"+f+"}"),f=(u?f.replace(C,""):f).replace(E,"$1").replace(O,"$1;"),f="function("+e+"){"+(l?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}"; +try{var c=Yt(r,"return "+f).apply(v,o)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.unescape=function(n){return null==n?"":re(n).replace(Qe,pt)},y.uniqueId=function(n){var t=++d;return re(null==n?"":n)+t},y.all=jt,y.any=Nt,y.detect=xt,y.findWhere=xt,y.foldl=At,y.foldr=It,y.include=wt,y.inject=At,er(y,function(n,t){y.prototype[t]||(y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return me.apply(t,arguments),t=n.apply(y,t),e?new m(t,e):t})}),y.first=Rt,y.last=function(n,t,e){if(n){var r=0,u=n.length; +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[u-1];return g(n,Be(0,u-r))}},y.sample=function(n,t,e){return Ke(n)||(n=Dt(n)),null==t||e?n[Ht(n.length-1)]:(n=Bt(n),n.length=Ne(Be(0,t),n.length),n)},y.take=Rt,y.head=Rt,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="1.3.1",y.prototype.chain=function(){return this.__chain__=!0,this +},y.prototype.toString=function(){return re(this.__wrapped__)},y.prototype.value=Ut,y.prototype.valueOf=Ut,Ye(["join","pop","shift"],function(n){var t=oe[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=oe[n];y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ye(["concat","slice","splice"],function(n){var t=oe[n];y.prototype[n]=function(){return new m(t.apply(this.__wrapped__,arguments),this.__chain__) +}}),Te.spliceObjects||Ye(["pop","shift","splice"],function(n){var t=oe[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,A=/\w*$/,I=/^function[ \n\r\t]+\w/,B=/<%=([\s\S]+?)%>/g,N=RegExp("^["+x+"]*0+(?=.$)"),D=/($^)/,P=(P=/\bthis\b/)&&P.test(h)&&P,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(" "),z="[object Arguments]",L="[object Array]",T="[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[z]=U[L]=U[T]=U[q]=U[G]=U[J]=U[M]=U[H]=!0;var V={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},Q={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},X=V[typeof window]&&window||this,Y=V[typeof exports]&&exports,Z=V[typeof module]&&module&&module.exports==Y&&module,nt=V[typeof global]&&global;!nt||nt.global!==nt&&nt.window!==nt||(X=nt);var tt=h();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(X._=tt, define(function(){return tt +})):Y&&!Y.nodeType?Z?(Z.exports=tt)._=tt:Y._=tt:X._=tt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 98740742e..b312b8a93 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -54,6 +54,9 @@ /** Used to match regexp flags from their coerced string values */ var reFlags = /\w*$/; + /** Used to detected named functions */ + var reFuncName = /^function[ \n\r\t]+\w/; + /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -609,6 +612,14 @@ */ support.fastBind = nativeBind && !isV8; + /** + * Detect if `Function#name` is supported (all but IE). + * + * @memberOf _.support + * @type boolean + */ + support.funcNames = typeof Function.name == 'string'; + /** * By default, the template delimiters used by Lo-Dash are similar to those in * embedded Ruby (ERB). Change the following template settings to use alternative @@ -780,14 +791,20 @@ if (typeof thisArg == 'undefined') { return func; } - var bindData = !func.name || func.__bindData__; + var bindData = func.__bindData__ || (support.funcNames && !func.name); if (typeof bindData == 'undefined') { - // checks if `func` references the `this` keyword and stores the result - bindData = !reThis || reThis.test(fnToString.call(func)); - setBindData(func, bindData); + var source = reThis && fnToString.call(func); + if (!support.funcNames && source && !reFuncName.test(source)) { + bindData = true; + } + if (support.funcNames || !bindData) { + // checks if `func` references the `this` keyword and stores the result + bindData = !reThis || reThis.test(source); + setBindData(func, bindData); + } } // exit early if there are no `this` references or `func` is bound - if (bindData !== true && !(bindData && bindData[1] & 1)) { + if (bindData !== true && (bindData && bindData[1] & 1)) { return func; } switch (argCount) { diff --git a/dist/lodash.min.js b/dist/lodash.min.js index a2a6404ca..e380b7b8b 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -4,49 +4,49 @@ * Build: `lodash modern -o ./dist/lodash.js` */ ;(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?i():s;if(v){var g=o(h);g?(f=t,h=g):(v=!1,h=u?h:(c(h),s)) -}for(;++af(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.b),p(h)):u&&c(h),s}function ut(n){return function(t,e,r){var u={};e=Q.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Ie(0,o+e):e)||0,ze(n)?a=-1o&&(o=i)}}else t=!t&&mt(n)?r:Q.createCallback(t,e,3),kt(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Et(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Ht(r);++earguments.length;t=Z(t,r,4);var o=-1,a=n.length;if(typeof a=="number")for(u&&(e=n[++o]);++oarguments.length;return t=Z(t,r,4),xt(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function At(n){var t=-1,e=n?n.length:0,r=Ht(typeof e=="number"?e:0);return kt(n,function(n){var e=Vt(++t);r[t]=r[e],r[e]=n}),r}function Nt(n,t,e){var r;t=Q.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(i);c?(u=t,i=c):l=!1}for(;++ru(i,c)&&f.push(c);return l&&p(i),f}function $t(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&null!=t){var o=-1;for(t=Q.createCallback(t,e,3);++or?Ie(0,u+r):r||0}else if(r)return r=Tt(t,e),t[r]===e?r:-1; -return n(t,e,r)}function Ft(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=Q.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++tl&&(a=n.apply(f,o));else{s||g||(c=i);var e=p-(i-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:E,variable:"",imports:{_:Q}};var Te=we?function(n,t){var e=f();e.value=t,we(n,"__bindData__",e),p(e)}:l,ze=xe||function(n){return n&&typeof n=="object"?be.call(n)==$:!1},qe=Ee?function(n){return gt(n)?Ee(n):[]}:H,We={"&":"&","<":"<",">":">",'"':""","'":"'"},Pe=vt(We),Ke=te("("+qe(Pe).join("|")+")","g"),Le=te("["+qe(We).join("")+"]","g"),Me=ut(function(n,t,e){ve.call(n,e)?n[e]++:n[e]=1 -}),Ue=ut(function(n,t,e){(ve.call(n,e)?n[e]:n[e]=[]).push(t)}),Ve=ut(function(n,t,e){n[e]=t});$e&&G&&typeof ye=="function"&&(Lt=function(n){if(!ht(n))throw new re;return ye.apply(e,arguments)});var Ge=8==Ae(w+"08")?Ae:function(n,t){return Ae(mt(n)?n.replace(I,""):n,t||0)};return Q.after=function(n,t){if(!ht(t))throw new re;return function(){return 1>--n?t.apply(this,arguments):void 0}},Q.assign=V,Q.at=function(n){for(var t=arguments,e=-1,r=nt(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Ht(t);++e=b&&o(a?r[a]:g)}n:for(;++l(m?t(m,y):s(g,y))){for(a=u,(m||g).push(y);--a;)if(m=f[a],0>(m?t(m,y):s(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&p(m); -return c(f),c(g),h},Q.invert=vt,Q.invoke=function(n,t){var e=Re.call(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Ht(typeof o=="number"?o:0);return kt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},Q.keys=qe,Q.map=Ct,Q.max=Ot,Q.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0];return ve.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!ht(n))throw new re;return e.cache={},e},Q.merge=function(n){var t=arguments,e=2;if(!gt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(a,e))&&(o[e]=n) -}),o},Q.once=function(n){var t,e;if(!ht(n))throw new re;return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},Q.pairs=function(n){for(var t=-1,e=qe(n),r=e.length,u=Ht(r);++te?Ie(0,r+e):Se(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},Q.mixin=Ut,Q.noConflict=function(){return e._=ae,this -},Q.parseInt=Ge,Q.random=Vt,Q.reduce=It,Q.reduceRight=St,Q.result=function(n,t){var e=n?n[t]:h;return ht(e)?n[t]():e},Q.runInContext=v,Q.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qe(n).length},Q.some=Nt,Q.sortedIndex=Tt,Q.template=function(n,t,e){var r=Q.templateSettings;n||(n=""),e=M({},e,r);var u,o=M({},e.imports,r.imports),r=qe(o),o=_t(o),i=0,f=e.interpolate||S,l="__p+='",f=te((e.escape||S).source+"|"+f.source+"|"+(f===E?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(i,c).replace(N,a),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t -}),l+="';\n",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=Xt(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Q.unescape=function(n){return null==n?"":ee(n).replace(Ke,lt)},Q.uniqueId=function(n){var t=++m;return ee(null==n?"":n)+t -},Q.all=dt,Q.any=Nt,Q.detect=jt,Q.findWhere=jt,Q.foldl=It,Q.foldr=St,Q.include=bt,Q.inject=It,y(Q,function(n,t){Q.prototype[t]||(Q.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return ge.apply(t,arguments),t=n.apply(Q,t),e?new X(t,e):t})}),Q.first=$t,Q.last=function(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&null!=t){var o=u;for(t=Q.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n[u-1];return s(n,Ie(0,u-r))}},Q.sample=function(n,t,e){return ze(n)||(n=Rt(n)),null==t||e?n[Vt(n.length-1)]:(n=At(n),n.length=Se(Ie(0,t),n.length),n) -},Q.take=$t,Q.head=$t,y(Q,function(n,t){var e="sample"!==t;Q.prototype[t]||(Q.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 X(o,u):o})}),Q.VERSION="1.3.1",Q.prototype.chain=function(){return this.__chain__=!0,this},Q.prototype.toString=function(){return ee(this.__wrapped__)},Q.prototype.value=Gt,Q.prototype.valueOf=Gt,kt(["join","pop","shift"],function(n){var t=ue[n];Q.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); -return n?new X(e,n):e}}),kt(["push","reverse","sort","unshift"],function(n){var t=ue[n];Q.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),kt(["concat","slice","splice"],function(n){var t=ue[n];Q.prototype[n]=function(){return new X(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Q}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*$/,E=/<%=([\s\S]+?)%>/g,I=RegExp("^["+w+"]*0+(?=.$)"),S=/($^)/,A=(A=/\bthis\b/)&&A.test(v)&&A,N=/['\n\r\t\u2028\u2029\\]/g,R="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),B="[object Arguments]",$="[object Array]",D="[object Boolean]",F="[object Date]",T="[object Function]",z="[object Number]",q="[object Object]",W="[object RegExp]",P="[object String]",K={}; -K[T]=!1,K[B]=K[$]=K[D]=K[F]=K[z]=K[q]=K[W]=K[P]=!0;var L={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},M={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},U=L[typeof window]&&window||this,V=L[typeof exports]&&exports,G=L[typeof module]&&module&&module.exports==V&&module,H=L[typeof global]&&global;!H||H.global!==H&&H.window!==H||(U=H);var J=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(U._=J, define(function(){return J -})):V&&!V.nodeType?G?(G.exports=J)._=J:V._=J:U._=J}).call(this); \ No newline at end of file +}}function r(n){return n.charCodeAt(0)}function u(n,t){var e=n.l,r=t.l;if(e!==r){if(e>r||typeof e=="undefined")return 1;if(ee?0:e);++r=b&&f===n,h=u||v?i():s;if(v){var g=o(h);g?(f=t,h=g):(v=!1,h=u?h:(c(h),s))}for(;++af(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.b),p(h)):u&&c(h),s}function ot(n){return function(t,e,r){var u={};e=X.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Ie(0,o+e):e)||0,qe(n)?a=-1o&&(o=i)}}else t=!t&&_t(n)?r:X.createCallback(t,e,3),xt(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Et(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Jt(r);++earguments.length;t=nt(t,r,4);var o=-1,a=n.length;if(typeof a=="number")for(u&&(e=n[++o]);++oarguments.length;return t=nt(t,r,4),Ct(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function At(n){var t=-1,e=n?n.length:0,r=Jt(typeof e=="number"?e:0);return xt(n,function(n){var e=Gt(++t);r[t]=r[e],r[e]=n}),r}function Rt(n,t,e){var r;t=X.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(i);c?(u=t,i=c):l=!1}for(;++ru(i,c)&&f.push(c);return l&&p(i),f}function Dt(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&null!=t){var o=-1;for(t=X.createCallback(t,e,3);++or?Ie(0,u+r):r||0}else if(r)return r=zt(t,e),t[r]===e?r:-1; +return n(t,e,r)}function Tt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=X.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++tl&&(a=n.apply(f,o));else{s||g||(c=i);var e=p-(i-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:E,variable:"",imports:{_:X}};var ze=je?function(n,t){var e=f();e.value=t,je(n,"__bindData__",e),p(e)}:l,qe=Ce||function(n){return n&&typeof n=="object"?de.call(n)==D:!1},We=Ee?function(n){return yt(n)?Ee(n):[]}:J,Pe={"&":"&","<":"<",">":">",'"':""","'":"'"},Ke=ht(Pe),Le=ee("("+We(Ke).join("|")+")","g"),Me=ee("["+We(Pe).join("")+"]","g"),Ue=ot(function(n,t,e){he.call(n,e)?n[e]++:n[e]=1 +}),Ve=ot(function(n,t,e){(he.call(n,e)?n[e]:n[e]=[]).push(t)}),Ge=ot(function(n,t,e){n[e]=t});De&&H&&typeof me=="function"&&(Mt=function(n){if(!gt(n))throw new ue;return me.apply(e,arguments)});var He=8==Ae(w+"08")?Ae:function(n,t){return Ae(_t(n)?n.replace(I,""):n,t||0)};return X.after=function(n,t){if(!gt(t))throw new ue;return function(){return 1>--n?t.apply(this,arguments):void 0}},X.assign=G,X.at=function(n){for(var t=arguments,e=-1,r=tt(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Jt(t);++e=b&&o(a?r[a]:g)}n:for(;++l(m?t(m,y):s(g,y))){for(a=u,(m||g).push(y);--a;)if(m=f[a],0>(m?t(m,y):s(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&p(m); +return c(f),c(g),h},X.invert=ht,X.invoke=function(n,t){var e=Be.call(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Jt(typeof o=="number"?o:0);return xt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},X.keys=We,X.map=Ot,X.max=Nt,X.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0];return he.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!gt(n))throw new ue;return e.cache={},e},X.merge=function(n){var t=arguments,e=2;if(!yt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(a,e))&&(o[e]=n) +}),o},X.once=function(n){var t,e;if(!gt(n))throw new ue;return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},X.pairs=function(n){for(var t=-1,e=We(n),r=e.length,u=Jt(r);++te?Ie(0,r+e):Se(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},X.mixin=Vt,X.noConflict=function(){return e._=ie,this +},X.parseInt=He,X.random=Gt,X.reduce=It,X.reduceRight=St,X.result=function(n,t){var e=n?n[t]:h;return gt(e)?n[t]():e},X.runInContext=v,X.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:We(n).length},X.some=Rt,X.sortedIndex=zt,X.template=function(n,t,e){var r=X.templateSettings;n||(n=""),e=U({},e,r);var u,o=U({},e.imports,r.imports),r=We(o),o=bt(o),i=0,f=e.interpolate||S,l="__p+='",f=ee((e.escape||S).source+"|"+f.source+"|"+(f===E?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(i,c).replace(R,a),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t +}),l+="';\n",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=Yt(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},X.unescape=function(n){return null==n?"":re(n).replace(Le,ct)},X.uniqueId=function(n){var t=++m;return re(null==n?"":n)+t +},X.all=wt,X.any=Rt,X.detect=kt,X.findWhere=kt,X.foldl=It,X.foldr=St,X.include=dt,X.inject=It,y(X,function(n,t){X.prototype[t]||(X.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return ye.apply(t,arguments),t=n.apply(X,t),e?new Y(t,e):t})}),X.first=Dt,X.last=function(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&null!=t){var o=u;for(t=X.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n[u-1];return s(n,Ie(0,u-r))}},X.sample=function(n,t,e){return qe(n)||(n=Bt(n)),null==t||e?n[Gt(n.length-1)]:(n=At(n),n.length=Se(Ie(0,t),n.length),n) +},X.take=Dt,X.head=Dt,y(X,function(n,t){var e="sample"!==t;X.prototype[t]||(X.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 Y(o,u):o})}),X.VERSION="1.3.1",X.prototype.chain=function(){return this.__chain__=!0,this},X.prototype.toString=function(){return re(this.__wrapped__)},X.prototype.value=Ht,X.prototype.valueOf=Ht,xt(["join","pop","shift"],function(n){var t=oe[n];X.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); +return n?new Y(e,n):e}}),xt(["push","reverse","sort","unshift"],function(n){var t=oe[n];X.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),xt(["concat","slice","splice"],function(n){var t=oe[n];X.prototype[n]=function(){return new Y(t.apply(this.__wrapped__,arguments),this.__chain__)}}),X}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*$/,N=/^function[ \n\r\t]+\w/,E=/<%=([\s\S]+?)%>/g,I=RegExp("^["+w+"]*0+(?=.$)"),S=/($^)/,A=(A=/\bthis\b/)&&A.test(v)&&A,R=/['\n\r\t\u2028\u2029\\]/g,B="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),$="[object Arguments]",D="[object Array]",F="[object Boolean]",T="[object Date]",z="[object Function]",q="[object Number]",W="[object Object]",P="[object RegExp]",K="[object String]",L={}; +L[z]=!1,L[$]=L[D]=L[F]=L[T]=L[q]=L[W]=L[P]=L[K]=!0;var M={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},U={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},V=M[typeof window]&&window||this,G=M[typeof exports]&&exports,H=M[typeof module]&&module&&module.exports==G&&module,J=M[typeof global]&&global;!J||J.global!==J&&J.window!==J||(V=J);var Q=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(V._=Q, define(function(){return Q +})):G&&!G.nodeType?H?(H.exports=Q)._=Q:G._=Q:V._=Q}).call(this); \ No newline at end of file diff --git a/lodash.js b/lodash.js index c487fe78b..8a66770e4 100644 --- a/lodash.js +++ b/lodash.js @@ -56,6 +56,9 @@ /** Used to match regexp flags from their coerced string values */ var reFlags = /\w*$/; + /** Used to detected named functions */ + var reFuncName = /^function[ \n\r\t]+\w/; + /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -711,6 +714,15 @@ */ support.fastBind = nativeBind && !isV8; + + /** + * Detect if `Function#name` is supported (all but IE). + * + * @memberOf _.support + * @type boolean + */ + support.funcNames = typeof Function.name == 'string'; + /** * Detect if own properties are iterated after inherited properties (all but IE < 9). * @@ -1067,14 +1079,20 @@ if (typeof thisArg == 'undefined') { return func; } - var bindData = !func.name || func.__bindData__; + var bindData = func.__bindData__ || (support.funcNames && !func.name); if (typeof bindData == 'undefined') { - // checks if `func` references the `this` keyword and stores the result - bindData = !reThis || reThis.test(fnToString.call(func)); - setBindData(func, bindData); + var source = reThis && fnToString.call(func); + if (!support.funcNames && source && !reFuncName.test(source)) { + bindData = true; + } + if (support.funcNames || !bindData) { + // checks if `func` references the `this` keyword and stores the result + bindData = !reThis || reThis.test(source); + setBindData(func, bindData); + } } // exit early if there are no `this` references or `func` is bound - if (bindData !== true && !(bindData && bindData[1] & 1)) { + if (bindData !== true && (bindData && bindData[1] & 1)) { return func; } switch (argCount) {