From fdbe4c5bd51f358042a430e7f7312dc9cac8d82f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 24 Oct 2013 22:28:45 -0700 Subject: [PATCH] Avoid broken `Function#bind` in Narwhal. --- dist/lodash.compat.js | 21 ++++++++--- dist/lodash.compat.min.js | 63 +++++++++++++++++---------------- dist/lodash.js | 21 ++++++++--- dist/lodash.min.js | 66 +++++++++++++++++------------------ dist/lodash.underscore.js | 20 ++++++++--- dist/lodash.underscore.min.js | 58 +++++++++++++++--------------- lodash.js | 21 ++++++++--- test/test.js | 7 ++-- 8 files changed, 161 insertions(+), 116 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 7bcdee341..8e3b1b485 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -505,11 +505,14 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = context._; + /** Used to resolve the internal [[Class]] of values */ + var toString = objectProto.toString; + /** Used to detect if a method is native */ var reNative = RegExp('^' + - String(objectProto.valueOf) + String(toString) .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - .replace(/valueOf|for [^\]]+/g, '.+?') + '$' + .replace(/toString| for [^\]]+/g, '.*?') + '$' ); /** Native method shortcuts */ @@ -525,10 +528,10 @@ setImmediate = context.setImmediate, setTimeout = context.setTimeout, splice = arrayRef.splice, - toString = objectProto.toString, unshift = arrayRef.unshift; var defineProperty = (function() { + // IE 8 that only accepts DOM elements try { var o = {}, func = reNative.test(func = Object.defineProperty) && func, @@ -538,8 +541,7 @@ }()); /* Native method shortcuts for methods with the same name as other `lodash` methods */ - var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind, - nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, + var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = context.isFinite, nativeIsNaN = context.isNaN, @@ -549,6 +551,15 @@ nativeParseInt = context.parseInt, nativeRandom = Math.random; + var nativeBind = (function() { + // Narwhal doesn't accept `undefined` as the `thisArg` + try { + var result = toString.bind; + return reNative.test(result) && result.bind() && result; + } catch(e) { } + return false; + }()); + /** Detect various environments */ var isIeOpera = reNative.test(context.attachEvent), isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera); diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 891359029..b6209111b 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,51 +5,52 @@ */ ;(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);++re?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 lt(n){return function(t,e,r){var u={};if(e=y.createCallback(e,r,3),Ge(t)){r=-1;for(var o=t.length;++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 lt(n){return function(t,e,r){var u={};if(e=y.createCallback(e,r,3),Ge(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||Ke.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+"}")(tt,K,fe,de,_,yt,Ge,xt,X.f,le,Y,qe,H,ce,ke) -}function st(n){return Qe[n]}function gt(){var t=(t=y.indexOf)===Tt?n:t;return t}function ht(n){var t,e;return!n||ke.call(n)!=J||(t=n.constructor,bt(t)&&!(t instanceof t))||!Ke.argsClass&&yt(n)||!Ke.nodeClass&&l(n)?!1:Ke.ownLast?(rr(n,function(n,t,r){return e=de.call(r,t),!1}),false!==e):(rr(n,function(n,t){e=t}),typeof e=="undefined"||de.call(n,e))}function vt(n){return Xe[n]}function yt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ke.call(n)==L||!1}function mt(n,t,e){var r=Me(n),u=r.length; -for(t=tt(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function dt(n){var t=[];return rr(n,function(n,e){bt(n)&&t.push(e)}),t.sort()}function _t(n){for(var t=-1,e=Me(n),r=e.length,u={};++te?Pe(0,o+e):e)||0,Ge(n)?a=-1k;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||Ke.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+"}")(tt,K,fe,_e,_,yt,Ge,xt,X.f,le,Y,qe,H,ce,se) +}function st(n){return Qe[n]}function gt(){var t=(t=y.indexOf)===Tt?n:t;return t}function ht(n){var t,e;return!n||se.call(n)!=J||(t=n.constructor,bt(t)&&!(t instanceof t))||!Ke.argsClass&&yt(n)||!Ke.nodeClass&&l(n)?!1:Ke.ownLast?(rr(n,function(n,t,r){return e=_e.call(r,t),!1}),false!==e):(rr(n,function(n,t){e=t}),typeof e=="undefined"||_e.call(n,e))}function vt(n){return Xe[n]}function yt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&se.call(n)==L||!1}function mt(n,t,e){var r=Me(n),u=r.length; +for(t=tt(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function dt(n){var t=[];return rr(n,function(n,e){bt(n)&&t.push(e)}),t.sort()}function _t(n){for(var t=-1,e=Me(n),r=e.length,u={};++te?Ne(0,o+e):e)||0,Ge(n)?a=-1o&&(o=i)}}else t=!t&&xt(n)?r:y.createCallback(t,e,3),nr(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o }function Nt(n,t,e,r){var u=3>arguments.length;if(t=tt(t,r,4),Ge(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=tt(t,r,4),At(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function Rt(n){var t=-1,e=n?n.length:0,r=Xt(typeof e=="number"?e:0);return It(n,function(n){var e=it(0,++t);r[t]=r[e],r[e]=n}),r}function Ft(n,t,e){var r;if(t=y.createCallback(t,e,3),Ge(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 Lt(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?Pe(0,u+r):r||0}else if(r)return r=qt(t,e),t[r]===e?r:-1; -return n(t,e,r)}function zt(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:B,variable:"",imports:{_:y}},Ie||(Z=function(n){if(wt(n)){c.prototype=n;var t=new c;c.prototype=null}return t||{}});var We=Oe?function(n,t){Q.value=t,Oe(n,"__bindData__",Q)}:c;Ke.argsClass||(yt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&de.call(n,"callee")||!1});var Ge=Ae||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ke.call(n)==T||!1 -},Je=pt({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),Me=Ne?function(n){return wt(n)?Ke.enumPrototypes&&typeof n=="function"||Ke.nonEnumArgs&&n.length&&yt(n)?Je(n):Ne(n):[]}:Je,He={a:"g,e,K",i:"e=e&&typeof K=='undefined'?e:d(e,K,3)",b:"typeof u=='number'",v:Me,g:"if(e(t[n],n,g)===false)return E"},Ue={a:"z,H,l",i:"var a=arguments,b=0,c=typeof l=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Xe=_t(Qe),Ye=ue("("+Me(Xe).join("|")+")","g"),Ze=ue("["+Me(Qe).join("")+"]","g"),nr=pt(He),tr=pt(Ue,{i:Ue.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]"}),er=pt(Ue),rr=pt(He,Ve,{j:!1}),ur=pt(He,Ve); -bt(/x/)&&(bt=function(n){return typeof n=="function"&&ke.call(n)==W});var or=me?function(n){if(!n||ke.call(n)!=J||!Ke.argsClass&&yt(n))return!1;var t=n.valueOf,e=typeof t=="function"&&(e=me(t))&&me(e);return e?n==e||me(n)==e:ht(n)}:ht,ar=lt(function(n,t,e){de.call(n,e)?n[e]++:n[e]=1}),ir=lt(function(n,t,e){(de.call(n,e)?n[e]:n[e]=[]).push(t)}),fr=lt(function(n,t,e){n[e]=t}),lr=Bt;Te&&rt&&typeof je=="function"&&(Ht=function(n){if(!bt(n))throw new ae;return je.apply(e,arguments)});var cr=8==Fe(x+"08")?Fe:function(n,t){return Fe(xt(n)?n.replace(D,""):n,t||0) +});return!!r}function $t(e){var r=-1,u=gt(),a=e?e.length:0,i=et(arguments,!0,!0,1),f=[],l=a>=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 Lt(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=qt(t,e),t[r]===e?r:-1; +return n(t,e,r)}function zt(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:B,variable:"",imports:{_:y}},Se||(Z=function(n){if(wt(n)){c.prototype=n;var t=new c;c.prototype=null}return t||{}});var We=Oe?function(n,t){Q.value=t,Oe(n,"__bindData__",Q)}:c;Ke.argsClass||(yt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&_e.call(n,"callee")||!1});var Ge=Ie||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&se.call(n)==T||!1 +},Je=pt({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),Me=De?function(n){return wt(n)?Ke.enumPrototypes&&typeof n=="function"||Ke.nonEnumArgs&&n.length&&yt(n)?Je(n):De(n):[]}:Je,He={a:"g,e,K",i:"e=e&&typeof K=='undefined'?e:d(e,K,3)",b:"typeof u=='number'",v:Me,g:"if(e(t[n],n,g)===false)return E"},Ue={a:"z,H,l",i:"var a=arguments,b=0,c=typeof l=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Xe=_t(Qe),Ye=ue("("+Me(Xe).join("|")+")","g"),Ze=ue("["+Me(Qe).join("")+"]","g"),nr=pt(He),tr=pt(Ue,{i:Ue.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]"}),er=pt(Ue),rr=pt(He,Ve,{j:!1}),ur=pt(He,Ve); +bt(/x/)&&(bt=function(n){return typeof n=="function"&&se.call(n)==W});var or=de?function(n){if(!n||se.call(n)!=J||!Ke.argsClass&&yt(n))return!1;var t=n.valueOf,e=typeof t=="function"&&(e=de(t))&&de(e);return e?n==e||de(n)==e:ht(n)}:ht,ar=lt(function(n,t,e){_e.call(n,e)?n[e]++:n[e]=1}),ir=lt(function(n,t,e){(_e.call(n,e)?n[e]:n[e]=[]).push(t)}),fr=lt(function(n,t,e){n[e]=t}),lr=Bt;Te&&rt&&typeof xe=="function"&&(Ht=function(n){if(!bt(n))throw new ae;return xe.apply(e,arguments)});var cr=8==Re(x+"08")?Re:function(n,t){return Re(xt(n)?n.replace(D,""):n,t||0) };return y.after=function(n,t){if(!bt(t))throw new ae;return function(){return 1>--n?t.apply(this,arguments):void 0}},y.assign=tr,y.at=function(n){var t=arguments,e=-1,r=et(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Xt(t);for(Ke.unindexedChars&&xt(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=_t,y.invoke=function(n,t){var e=g(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Xt(typeof o=="number"?o:0);return It(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},y.keys=Me,y.map=Bt,y.max=Dt,y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0]; -return de.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!bt(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(a,e))&&(o[e]=n)}),o},y.once=function(n){var t,e;if(!bt(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=Me(n),r=e.length,u=Xt(r);++te?Pe(0,r+e):Re(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},y.mixin=Vt,y.noConflict=function(){return e._=pe,this},y.parseInt=cr,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=$e(),Re(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):it(n,t) +}),r},y.findLastIndex=function(n,t,e){var r=n?n.length:0;for(t=y.createCallback(t,e,3);r--;)if(t(n[r],r,n))return r;return-1},y.findLastKey=function(n,t,e){var r;return t=y.createCallback(t,e,3),mt(n,function(n,e,u){return t(n,e,u)?(r=e,!1):void 0}),r},y.has=function(n,t){return n?_e.call(n,t):!1},y.identity=Ut,y.indexOf=Tt,y.isArguments=yt,y.isArray=Ge,y.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&se.call(n)==z||!1},y.isDate=function(n){return n&&typeof n=="object"&&se.call(n)==q||!1 +},y.isElement=function(n){return n&&1===n.nodeType||!1},y.isEmpty=function(n){var t=!0;if(!n)return t;var e=se.call(n),r=n.length;return e==T||e==H||(Ke.argsClass?e==L:yt(n))||e==J&&typeof r=="number"&&bt(n.splice)?!r:(ur(n,function(){return t=!1}),t)},y.isEqual=function(n,t,e,r){return ut(n,t,typeof e=="function"&&tt(e,r,2))},y.isFinite=function(n){return Ae(n)&&!Be(parseFloat(n))},y.isFunction=bt,y.isNaN=function(n){return jt(n)&&n!=+n},y.isNull=function(n){return null===n},y.isNumber=jt,y.isObject=wt,y.isPlainObject=or,y.isRegExp=function(n){return n&&Y[typeof n]&&se.call(n)==M||!1 +},y.isString=xt,y.isUndefined=function(n){return typeof n=="undefined"},y.lastIndexOf=function(n,t,e){var r=n?n.length:0;for(typeof e=="number"&&(r=(0>e?Ne(0,r+e):Pe(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},y.mixin=Vt,y.noConflict=function(){return e._=pe,this},y.parseInt=cr,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)):it(n,t) },y.reduce=Nt,y.reduceRight=Pt,y.result=function(n,t){if(n){var e=n[t];return bt(e)?n[t]():e}},y.runInContext=h,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Me(n).length},y.some=Ft,y.sortedIndex=qt,y.template=function(n,t,e){var r=y.templateSettings;n=oe(n||""),e=er({},e,r);var u,o=er({},e.imports,r.imports),r=Me(o),o=Ct(o),i=0,f=e.interpolate||N,l="__p+='",f=ue((e.escape||N).source+"|"+f.source+"|"+(f===B?S:N).source+"|"+(e.evaluate||N).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=ne(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?"":oe(n).replace(Ye,vt)},y.uniqueId=function(n){var t=++d;return oe(null==n?"":n)+t -},y.all=Et,y.any=Ft,y.detect=St,y.findWhere=St,y.foldl=Nt,y.foldr=Pt,y.include=kt,y.inject=Nt,ur(y,function(n,t){y.prototype[t]||(y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return be.apply(t,arguments),t=n.apply(y,t),e?new m(t,e):t})}),y.first=Lt,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,Pe(0,u-r))},y.sample=function(n,t,e){return n&&typeof n.length!="number"?n=Ct(n):Ke.unindexedChars&&xt(n)&&(n=n.split("")),null==t||e?n?n[it(0,n.length-1)]:v:(n=Rt(n),n.length=Re(Pe(0,t),n.length),n) +},y.all=Et,y.any=Ft,y.detect=St,y.findWhere=St,y.foldl=Nt,y.foldr=Pt,y.include=kt,y.inject=Nt,ur(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 m(t,e):t})}),y.first=Lt,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=Ct(n):Ke.unindexedChars&&xt(n)&&(n=n.split("")),null==t||e?n?n[it(0,n.length-1)]:v:(n=Rt(n),n.length=Pe(Ne(0,t),n.length),n) },y.take=Lt,y.head=Lt,ur(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 oe(this.__wrapped__)},y.prototype.value=Qt,y.prototype.valueOf=Qt,nr(["join","pop","shift"],function(n){var t=ie[n];y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); return n?new m(e,n):e}}),nr(["push","reverse","sort","unshift"],function(n){var t=ie[n];y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),nr(["concat","slice","splice"],function(n){var t=ie[n];y.prototype[n]=function(){return new m(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Ke.spliceObjects||nr(["pop","shift","splice"],function(n){var t=ie[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/,B=/<%=([\s\S]+?)%>/g,D=RegExp("^["+x+"]*0+(?=.$)"),N=/($^)/,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={}; diff --git a/dist/lodash.js b/dist/lodash.js index 3197912f4..bc18ac00c 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -464,11 +464,14 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = context._; + /** Used to resolve the internal [[Class]] of values */ + var toString = objectProto.toString; + /** Used to detect if a method is native */ var reNative = RegExp('^' + - String(objectProto.valueOf) + String(toString) .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - .replace(/valueOf|for [^\]]+/g, '.+?') + '$' + .replace(/toString| for [^\]]+/g, '.*?') + '$' ); /** Native method shortcuts */ @@ -483,10 +486,10 @@ setImmediate = context.setImmediate, setTimeout = context.setTimeout, splice = arrayRef.splice, - toString = objectProto.toString, unshift = arrayRef.unshift; var defineProperty = (function() { + // IE 8 that only accepts DOM elements try { var o = {}, func = reNative.test(func = Object.defineProperty) && func, @@ -496,8 +499,7 @@ }()); /* Native method shortcuts for methods with the same name as other `lodash` methods */ - var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind, - nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, + var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = context.isFinite, nativeIsNaN = context.isNaN, @@ -507,6 +509,15 @@ nativeParseInt = context.parseInt, nativeRandom = Math.random; + var nativeBind = (function() { + // Narwhal doesn't accept `undefined` as the `thisArg` + try { + var result = toString.bind; + return reNative.test(result) && result.bind() && result; + } catch(e) { } + return false; + }()); + /** Detect various environments */ var isIeOpera = reNative.test(context.attachEvent), isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera); diff --git a/dist/lodash.min.js b/dist/lodash.min.js index cdc2468eb..7b3903d70 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);++re?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 lt(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?Re(0,o+e):e)||0,ze(n)?i=-1=b&&f===n,v=u||h?a():s;if(h){var g=o(v);g?(f=t,v=g):(h=!1,v=u?v:(c(v),s))}for(;++if(v,y))&&((u||h)&&v.push(y),s.push(g)) +}return h?(c(v.k),p(v)):u&&c(v),s}function lt(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,ze(n)?i=-1o&&(o=a)}}else t=!t&&jt(n)?r:Y.createCallback(t,e,3),Nt(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function At(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Xt(r);++earguments.length;t=rt(t,r,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(e=n[++o]);++oarguments.length;return t=rt(t,r,4),Et(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=Xt(typeof e=="number"?e:0);return Nt(n,function(n){var e=at(0,++t);r[t]=r[e],r[e]=n}),r}function Ft(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 Wt(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?Re(0,u+r):r||0}else if(r)return r=Pt(t,e),t[r]===e?r:-1;return n(t,e,r)}function zt(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}},Oe||(et=function(n){if(dt(n)){l.prototype=n;var t=new l;l.prototype=null}return t||{}});var qe=xe?function(n,t){U.value=t,xe(n,"__bindData__",U)}:l,ze=Ie||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&je.call(n)==$||!1},Pe=Se?function(n){return dt(n)?Se(n):[] -}:Q,Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},Le=_t(Ke),Me=ue("("+Pe(Le).join("|")+")","g"),Ue=ue("["+Pe(Ke).join("")+"]","g"),Ve=lt(function(n,t,e){ye.call(n,e)?n[e]++:n[e]=1}),Ge=lt(function(n,t,e){(ye.call(n,e)?n[e]:n[e]=[]).push(t)}),He=lt(function(n,t,e){n[e]=t});Fe&&X&&typeof be=="function"&&(Gt=function(n){if(!bt(n))throw new ie;return be.apply(e,arguments)});var Je=8==De(w+"08")?De:function(n,t){return De(jt(n)?n.replace(E,""):n,t||0)};return Y.after=function(n,t){if(!bt(t))throw new ie; +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 Wt(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=Pt(t,e),t[r]===e?r:-1;return n(t,e,r)}function zt(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||(et=function(n){if(dt(n)){l.prototype=n;var t=new l;l.prototype=null}return t||{}});var qe=xe?function(n,t){U.value=t,xe(n,"__bindData__",U)}:l,ze=Oe||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ce.call(n)==$||!1},Pe=Ee?function(n){return dt(n)?Ee(n):[] +}:Q,Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},Le=_t(Ke),Me=ue("("+Pe(Le).join("|")+")","g"),Ue=ue("["+Pe(Ke).join("")+"]","g"),Ve=lt(function(n,t,e){me.call(n,e)?n[e]++:n[e]=1}),Ge=lt(function(n,t,e){(me.call(n,e)?n[e]:n[e]=[]).push(t)}),He=lt(function(n,t,e){n[e]=t});Fe&&X&&typeof de=="function"&&(Gt=function(n){if(!bt(n))throw new ie;return de.apply(e,arguments)});var Je=8==Ae(w+"08")?Ae:function(n,t){return Ae(jt(n)?n.replace(E,""):n,t||0)};return Y.after=function(n,t){if(!bt(t))throw new ie; 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=ut(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Xt(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=_t,Y.invoke=function(n,t){var e=s(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,i=Xt(typeof o=="number"?o:0);return Nt(n,function(n){i[++r]=(u?t:n[t]).apply(n,e)}),i},Y.keys=Pe,Y.map=St,Y.max=Rt,Y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0]; -return ye.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!bt(n))throw new ie;return e.cache={},e},Y.merge=function(n){var t=arguments,e=2;if(!dt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3=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;v.push(y)}}for(;u--;)(m=f[u])&&p(m);return c(f),c(g),v},Y.invert=_t,Y.invoke=function(n,t){var e=s(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,i=Xt(typeof o=="number"?o:0);return Nt(n,function(n){i[++r]=(u?t:n[t]).apply(n,e)}),i},Y.keys=Pe,Y.map=St,Y.max=Rt,Y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0]; +return me.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!bt(n))throw new ie;return e.cache={},e},Y.merge=function(n){var t=arguments,e=2;if(!dt(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(!bt(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=Pe(n),r=e.length,u=Xt(r);++te?Re(0,r+e):Ae(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=Je,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=Be(),Ae(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):at(n,t) -},Y.reduce=Dt,Y.reduceRight=Bt,Y.result=function(n,t){if(n){var e=n[t];return bt(e)?n[t]():e}},Y.runInContext=v,Y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Pe(n).length},Y.some=Ft,Y.sortedIndex=Pt,Y.template=function(n,t,e){var r=Y.templateSettings;n=oe(n||""),e=G({},e,r);var u,o=G({},e.imports,r.imports),r=Pe(o),o=kt(o),a=0,f=e.interpolate||S,l="__p+='",f=ue((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=ne(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?"":oe(n).replace(Me,ht)},Y.uniqueId=function(n){var t=++m;return oe(null==n?"":n)+t -},Y.all=Ct,Y.any=Ft,Y.detect=It,Y.findWhere=It,Y.foldl=Dt,Y.foldr=Bt,Y.include=xt,Y.inject=Dt,y(Y,function(n,t){Y.prototype[t]||(Y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return _e.apply(t,arguments),t=n.apply(Y,t),e?new nt(t,e):t})}),Y.first=Wt,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,Re(0,u-r))},Y.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=kt(n)),null==t||e?n?n[at(0,n.length-1)]:h:(n=$t(n),n.length=Ae(Re(0,t),n.length),n) +}),r},Y.findLastIndex=function(n,t,e){var r=n?n.length:0;for(t=Y.createCallback(t,e,3);r--;)if(t(n[r],r,n))return r;return-1},Y.findLastKey=function(n,t,e){var r;return t=Y.createCallback(t,e,3),yt(n,function(n,e,u){return t(n,e,u)?(r=e,!1):void 0}),r},Y.has=function(n,t){return n?me.call(n,t):!1},Y.identity=Ht,Y.indexOf=qt,Y.isArguments=gt,Y.isArray=ze,Y.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&ce.call(n)==F||!1},Y.isDate=function(n){return n&&typeof n=="object"&&ce.call(n)==T||!1 +},Y.isElement=function(n){return n&&1===n.nodeType||!1},Y.isEmpty=function(n){var t=!0;if(!n)return t;var e=ce.call(n),r=n.length;return e==$||e==K||e==B||e==z&&typeof r=="number"&&bt(n.splice)?!r:(y(n,function(){return t=!1}),t)},Y.isEqual=function(n,t,e,r){return ot(n,t,typeof e=="function"&&rt(e,r,2))},Y.isFinite=function(n){return Ie(n)&&!Ne(parseFloat(n))},Y.isFunction=bt,Y.isNaN=function(n){return wt(n)&&n!=+n},Y.isNull=function(n){return null===n},Y.isNumber=wt,Y.isObject=dt,Y.isPlainObject=g,Y.isRegExp=function(n){return n&&typeof n=="object"&&ce.call(n)==P||!1 +},Y.isString=jt,Y.isUndefined=function(n){return typeof n=="undefined"},Y.lastIndexOf=function(n,t,e){var r=n?n.length:0;for(typeof e=="number"&&(r=(0>e?Se(0,r+e):Re(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=Je,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)):at(n,t) +},Y.reduce=Dt,Y.reduceRight=Bt,Y.result=function(n,t){if(n){var e=n[t];return bt(e)?n[t]():e}},Y.runInContext=h,Y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Pe(n).length},Y.some=Ft,Y.sortedIndex=Pt,Y.template=function(n,t,e){var r=Y.templateSettings;n=oe(n||""),e=G({},e,r);var u,o=G({},e.imports,r.imports),r=Pe(o),o=kt(o),a=0,f=e.interpolate||S,l="__p+='",f=ue((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=ne(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?"":oe(n).replace(Me,vt)},Y.uniqueId=function(n){var t=++m;return oe(null==n?"":n)+t +},Y.all=Ct,Y.any=Ft,Y.detect=It,Y.findWhere=It,Y.foldl=Dt,Y.foldr=Bt,Y.include=xt,Y.inject=Dt,y(Y,function(n,t){Y.prototype[t]||(Y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return be.apply(t,arguments),t=n.apply(Y,t),e?new nt(t,e):t})}),Y.first=Wt,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 s(n,Se(0,u-r))},Y.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=kt(n)),null==t||e?n?n[at(0,n.length-1)]:v:(n=$t(n),n.length=Re(Se(0,t),n.length),n) },Y.take=Wt,Y.head=Wt,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 oe(this.__wrapped__)},Y.prototype.value=Qt,Y.prototype.valueOf=Qt,Nt(["join","pop","shift"],function(n){var t=ae[n];Y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); -return n?new nt(e,n):e}}),Nt(["push","reverse","sort","unshift"],function(n){var t=ae[n];Y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Nt(["concat","slice","splice"],function(n){var t=ae[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(" "),B="[object Arguments]",$="[object Array]",F="[object Boolean]",T="[object Date]",W="[object Function]",q="[object Number]",z="[object Object]",P="[object RegExp]",K="[object String]",L={}; +return n?new nt(e,n):e}}),Nt(["push","reverse","sort","unshift"],function(n){var t=ae[n];Y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Nt(["concat","slice","splice"],function(n){var t=ae[n];Y.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Y}var v,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(" "),B="[object Arguments]",$="[object Array]",F="[object Boolean]",T="[object Date]",W="[object Function]",q="[object Number]",z="[object Object]",P="[object RegExp]",K="[object String]",L={}; L[W]=!1,L[B]=L[$]=L[F]=L[T]=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 +var Z=h();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 80ed830bb..563053db1 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -199,11 +199,14 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = root._; + /** Used to resolve the internal [[Class]] of values */ + var toString = objectProto.toString; + /** Used to detect if a method is native */ var reNative = RegExp('^' + - String(objectProto.valueOf) + String(toString) .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - .replace(/valueOf|for [^\]]+/g, '.+?') + '$' + .replace(/toString| for [^\]]+/g, '.*?') + '$' ); /** Native method shortcuts */ @@ -212,12 +215,10 @@ hasOwnProperty = objectProto.hasOwnProperty, now = reNative.test(now = Date.now) && now || function() { return +new Date; }, push = arrayRef.push, - toString = objectProto.toString, unshift = arrayRef.unshift; /* Native method shortcuts for methods with the same name as other `lodash` methods */ - var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind, - nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, + var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = root.isFinite, nativeIsNaN = root.isNaN, @@ -226,6 +227,15 @@ nativeMin = Math.min, nativeRandom = Math.random; + var nativeBind = (function() { + // Narwhal doesn't accept `undefined` as the `thisArg` + try { + var result = toString.bind; + return reNative.test(result) && result.bind() && result; + } catch(e) { } + return false; + }()); + /** Detect various environments */ var isIeOpera = reNative.test(root.attachEvent), isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera); diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 8ef5cb5b5..fe423401f 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -4,35 +4,35 @@ * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ ;(function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined")return 1;if(tt?0:t);++eu(f,c))&&(t&&f.push(c),i.push(a))}return i}function s(n){return function(r,t,e){var u={};t=L(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++eu(f,c))&&(t&&f.push(c),i.push(a))}return i}function s(n){return function(r,t,e){var u={};t=L(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++ee&&(e=t,u=n)});else for(;++ou&&(u=t); return u}function M(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++targuments.length;r=a(r,e,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(t=n[++o]);++oarguments.length;return r=a(r,e,4),F(n,function(n,e,o){t=u?(u=!1,n):r(t,n,e,o)}),t}function W(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0); -return k(n,function(n){var t;t=++r,t=0+Er(Wr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=L(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 U(n,r,t){var e=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=-1;for(r=L(r,t,3);++ie?$r(0,u+e):e||0}else if(e)return e=H(r,t),r[e]===t?e:-1;return n(r,t,e)}function G(n,r,t){if(typeof r!="number"&&null!=r){var e=0,o=-1,i=n?n.length:0;for(r=L(r,t,3);++o>>1,t(n[e])/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},kr||(f=function(n){if(A(n)){e.prototype=n;var r=new e;e.prototype=null}return r||{}}),m(arguments)||(m=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Tr.call(n,"callee")||!1});var Ur=Fr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Br.call(n)==ir||!1 -},Vr=function(n){var r,t=[];if(!n||!hr[typeof n])return t;for(r in n)Tr.call(n,r)&&t.push(r);return t},Gr=Mr?function(n){return A(n)?Mr(n):[]}:Vr,Hr={"&":"&","<":"<",">":">",'"':""","'":"'"},Jr=w(Hr),Kr=RegExp("("+Gr(Jr).join("|")+")","g"),Lr=RegExp("["+Gr(Hr).join("")+"]","g"),Qr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(r(n[t],t,n)===rr)break;return n},Xr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(Tr.call(n,t)&&r(n[t],t,n)===rr)break; -return n};x(/x/)&&(x=function(n){return typeof n=="function"&&"[object Function]"==Br.call(n)});var Yr=s(function(n,r,t){Tr.call(n,t)?n[t]++:n[t]=1}),Zr=s(function(n,r,t){(Tr.call(n,t)?n[t]:n[t]=[]).push(r)}),nt=s(function(n,r,t){n[t]=r});o.after=function(n,r){if(!x(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=K,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=w,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 k(n,function(n){f[++e]=(o?r:n[r]).apply(n,t)}),f},o.keys=Gr,o.map=q,o.max=D,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):tr+arguments[0];return Tr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e,o=-1,i=n?n.length:0;if(r||typeof i!="number")r=L(r,t,3),k(n,function(n,t,o){t=r(n,t,o),tr(t,u)&&(e[u]=n)}),e},o.once=function(n){var r,t;if(!x(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=Gr(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=Y,o.noConflict=function(){return vr._=jr,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+Er(Wr()*(r-n+1))},o.reduce=$,o.reduceRight=I,o.result=function(n,r){if(n){var t=n[r];return x(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0; -return typeof r=="number"?r:Gr(n).length},o.some=z,o.sortedIndex=H,o.template=function(n,r,e){var u=o,i=u.templateSettings;n=(n||"")+"",e=d({},e,i);var f=0,a="__p+='",i=e.variable;n.replace(RegExp((e.escape||er).source+"|"+(e.interpolate||er).source+"|"+(e.evaluate||er).source+"|$","g"),function(r,e,u,o,i){return a+=n.slice(f,i).replace(ur,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 c=Function("_","return "+a)(u)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},o.unescape=function(n){return null==n?"":(n+"").replace(Kr,y)},o.uniqueId=function(n){var r=++nr+"";return n?n+r:r},o.all=B,o.any=z,o.detect=R,o.findWhere=function(n,r){return C(n,r,!0)},o.foldl=$,o.foldr=I,o.include=S,o.inject=$,o.first=U,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=L(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n?n[o-1]:Z; -return u(n,$r(0,o-e))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=O(n)),null==r||t?n?n[0+Er(Wr()*(n.length-1-0+1))]:Z:(n=W(n),n.length=Ir($r(0,r),n.length),n)},o.take=U,o.head=U,Y(o),o.VERSION="2.2.1",o.prototype.chain=function(){return this.__chain__=!0,this},o.prototype.value=function(){return this.__wrapped__},k("pop push reverse shift sort splice unshift".split(" "),function(n){var r=br[n];o.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),Pr.spliceObjects||0!==n.length||delete n[0],this -}}),k(["concat","join","slice"],function(n){var r=br[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?(vr._=o, define(function(){return o})):yr&&mr?_r?(mr.exports=o)._=o:yr._=o:vr._=o}).call(this); \ No newline at end of file +return k(n,function(n){var t;t=++r,t=0+Tr(Ir()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=L(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 U(n,r,t){var e=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=-1;for(r=L(r,t,3);++ie?Mr(0,u+e):e||0}else if(e)return e=H(r,t),r[e]===t?e:-1;return n(r,t,e)}function G(n,r,t){if(typeof r!="number"&&null!=r){var e=0,o=-1,i=n?n.length:0;for(r=L(r,t,3);++o>>1,t(n[e])/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Rr||(f=function(n){if(A(n)){e.prototype=n;var r=new e;e.prototype=null}return r||{}}),m(arguments)||(m=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Or.call(n,"callee")||!1 +});var Ur=kr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xr.call(n)==ir||!1},Vr=function(n){var r,t=[];if(!n||!hr[typeof n])return t;for(r in n)Or.call(n,r)&&t.push(r);return t},Gr=Dr?function(n){return A(n)?Dr(n):[]}:Vr,Hr={"&":"&","<":"<",">":">",'"':""","'":"'"},Jr=w(Hr),Kr=RegExp("("+Gr(Jr).join("|")+")","g"),Lr=RegExp("["+Gr(Hr).join("")+"]","g"),Qr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(r(n[t],t,n)===rr)break;return n},Xr=function(n,r){var t; +if(!n||!hr[typeof n])return n;for(t in n)if(Or.call(n,t)&&r(n[t],t,n)===rr)break;return n};x(/x/)&&(x=function(n){return typeof n=="function"&&"[object Function]"==xr.call(n)});var Yr=s(function(n,r,t){Or.call(n,t)?n[t]++:n[t]=1}),Zr=s(function(n,r,t){(Or.call(n,t)?n[t]:n[t]=[]).push(r)}),nt=s(function(n,r,t){n[t]=r});o.after=function(n,r){if(!x(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=K,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=w,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 k(n,function(n){f[++e]=(o?r:n[r]).apply(n,t)}),f},o.keys=Gr,o.map=q,o.max=D,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):tr+arguments[0];return Or.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e,o=-1,i=n?n.length:0; +if(r||typeof i!="number")r=L(r,t,3),k(n,function(n,t,o){t=r(n,t,o),tr(t,u)&&(e[u]=n)}),e},o.once=function(n){var r,t;if(!x(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=Gr(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=Y,o.noConflict=function(){return vr._=jr,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+Tr(Ir()*(r-n+1))},o.reduce=$,o.reduceRight=I,o.result=function(n,r){if(n){var t=n[r]; +return x(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:Gr(n).length},o.some=z,o.sortedIndex=H,o.template=function(n,r,e){var u=o,i=u.templateSettings;n=(n||"")+"",e=d({},e,i);var f=0,a="__p+='",i=e.variable;n.replace(RegExp((e.escape||er).source+"|"+(e.interpolate||er).source+"|"+(e.evaluate||er).source+"|$","g"),function(r,e,u,o,i){return a+=n.slice(f,i).replace(ur,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 c=Function("_","return "+a)(u)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},o.unescape=function(n){return null==n?"":(n+"").replace(Kr,y)},o.uniqueId=function(n){var r=++nr+"";return n?n+r:r},o.all=B,o.any=z,o.detect=R,o.findWhere=function(n,r){return C(n,r,!0)},o.foldl=$,o.foldr=I,o.include=S,o.inject=$,o.first=U,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=L(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n?n[o-1]:Z;return u(n,Mr(0,o-e))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=O(n)),null==r||t?n?n[0+Tr(Ir()*(n.length-1-0+1))]:Z:(n=W(n),n.length=$r(Mr(0,r),n.length),n)},o.take=U,o.head=U,Y(o),o.VERSION="2.2.1",o.prototype.chain=function(){return this.__chain__=!0,this},o.prototype.value=function(){return this.__wrapped__},k("pop push reverse shift sort splice unshift".split(" "),function(n){var r=br[n]; +o.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),Pr.spliceObjects||0!==n.length||delete n[0],this}}),k(["concat","join","slice"],function(n){var r=br[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?(vr._=o, define(function(){return o})):yr&&mr?_r?(mr.exports=o)._=o:yr._=o:vr._=o}).call(this); \ No newline at end of file diff --git a/lodash.js b/lodash.js index ab573d59f..b2fba83e6 100644 --- a/lodash.js +++ b/lodash.js @@ -504,11 +504,14 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = context._; + /** Used to resolve the internal [[Class]] of values */ + var toString = objectProto.toString; + /** Used to detect if a method is native */ var reNative = RegExp('^' + - String(objectProto.valueOf) + String(toString) .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - .replace(/valueOf|for [^\]]+/g, '.+?') + '$' + .replace(/toString| for [^\]]+/g, '.*?') + '$' ); /** Native method shortcuts */ @@ -524,10 +527,10 @@ setImmediate = context.setImmediate, setTimeout = context.setTimeout, splice = arrayRef.splice, - toString = objectProto.toString, unshift = arrayRef.unshift; var defineProperty = (function() { + // IE 8 that only accepts DOM elements try { var o = {}, func = reNative.test(func = Object.defineProperty) && func, @@ -537,8 +540,7 @@ }()); /* Native method shortcuts for methods with the same name as other `lodash` methods */ - var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind, - nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, + var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = context.isFinite, nativeIsNaN = context.isNaN, @@ -548,6 +550,15 @@ nativeParseInt = context.parseInt, nativeRandom = Math.random; + var nativeBind = (function() { + // Narwhal doesn't accept `undefined` as the `thisArg` + try { + var result = toString.bind; + return reNative.test(result) && result.bind() && result; + } catch(e) { } + return false; + }()); + /** Detect various environments */ var isIeOpera = reNative.test(context.attachEvent), isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera); diff --git a/test/test.js b/test/test.js index d6fba5abb..cb5a43b0f 100644 --- a/test/test.js +++ b/test/test.js @@ -1228,8 +1228,9 @@ test('should return the function provided if already bound with `Function#bind`', 1, function() { function a() {} - if (Function.prototype.bind) { - var bound = a.bind(); + var bound = a.bind && a.bind({}); + if (bound && !bound.prototype) { + var bound = a.bind({}); strictEqual(_.createCallback(bound, {}), bound); } else { @@ -1254,7 +1255,7 @@ function a() {}; var b = function() {}; - if (_.support.funcNames || _.support.funcDecomp) { + if (defineProperty && _.support.funcDecomp) { _.createCallback(a, {}); ok('__bindData__' in a)