mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
Simplify _.size.
Former-commit-id: a7d3338cbd5784ec6b9b6a25e18acd9507f4b21c
This commit is contained in:
@@ -186,7 +186,7 @@ require({
|
||||
* `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L521-524)]
|
||||
* `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L616-635)]
|
||||
* `_.isElement` should use strict equality for its duck type check [[test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L731-740)]
|
||||
* `_.isEmpty` and `_.size` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L767-772)]
|
||||
* `_.isEmpty` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L767-772)]
|
||||
* `_.isEqual` should return `true` for like-objects from different documents [[test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L808-828)]
|
||||
* `_.isObject` should avoid V8 bug [#2291](http://code.google.com/p/v8/issues/detail?id=2291) [[#605](https://github.com/documentcloud/underscore/issues/605), [test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L836-848)]
|
||||
* `_.isNaN(new Number(NaN))` should return `true` [[test](https://github.com/bestiejs/lodash/blob/v0.6.1/test/test.js#L856-858)]
|
||||
|
||||
6
build.js
6
build.js
@@ -233,7 +233,7 @@
|
||||
'rest': [],
|
||||
'result': ['isFunction'],
|
||||
'shuffle': [],
|
||||
'size': ['isArguments', 'isFunction', 'keys'],
|
||||
'size': ['keys'],
|
||||
'some': ['identity'],
|
||||
'sortBy': [],
|
||||
'sortedIndex': ['bind'],
|
||||
@@ -610,7 +610,7 @@
|
||||
*/
|
||||
function removeNoArgsClass(source) {
|
||||
return removeVar(source, 'noArgsClass')
|
||||
// remove `noArgsClass` from `_.clone`, `_.isEqual`, and `_.size`
|
||||
// remove `noArgsClass` from `_.clone` and `_.isEqual`
|
||||
.replace(/ *\|\| *\(noArgsClass *&&[^)]+?\)\)/g, '')
|
||||
// remove `noArgsClass` from `_.isEqual`
|
||||
.replace(/if *\(noArgsClass[^}]+?}\n/, '');
|
||||
@@ -1111,7 +1111,7 @@
|
||||
if (isRemoved(source, 'clone', 'merge')) {
|
||||
source = removeFunction(source, 'isPlainObject');
|
||||
}
|
||||
if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual', 'size')) {
|
||||
if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual')) {
|
||||
source = removeNoArgsClass(source);
|
||||
}
|
||||
if (isRemoved(source, 'isEqual', 'isPlainObject')) {
|
||||
|
||||
@@ -1912,7 +1912,7 @@ initialize();
|
||||
Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`.
|
||||
|
||||
#### Arguments
|
||||
1. `object` *(Object)*: The object to inspect..
|
||||
1. `object` *(Object)*: The object to inspect.
|
||||
|
||||
#### Returns
|
||||
*(Array)*: Returns new array of key-value pairs.
|
||||
@@ -2025,8 +2025,8 @@ _.pluck(stooges, 'name');
|
||||
Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. If no arguments are passed `_.random` will act as `Math.random`.
|
||||
|
||||
#### Arguments
|
||||
1. `min` *(Number)*: The minimum possible value
|
||||
2. `max` *(Number)*: The maximum possible value
|
||||
1. `min` *(Number)*: The minimum possible value.
|
||||
2. `max` *(Number)*: The maximum possible value.
|
||||
|
||||
#### Returns
|
||||
*(Number)*: Returns the random number.
|
||||
|
||||
71
lodash.js
71
lodash.js
@@ -1920,45 +1920,6 @@
|
||||
'bottom': '}'
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the size of `value` by returning `value.length` if `value` is an
|
||||
* array, string, or `arguments` object. If `value` is an object, size is
|
||||
* determined by returning the number of own enumerable properties it has.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Objects
|
||||
* @param {Array|Object|String} value The value to inspect.
|
||||
* @returns {Number} Returns `value.length` or number of own enumerable properties.
|
||||
* @example
|
||||
*
|
||||
* _.size([1, 2]);
|
||||
* // => 2
|
||||
*
|
||||
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
|
||||
* // => 3
|
||||
*
|
||||
* _.size('curly');
|
||||
* // => 5
|
||||
*/
|
||||
function size(value) {
|
||||
if (!value) {
|
||||
return 0;
|
||||
}
|
||||
var className = toString.call(value),
|
||||
length = value.length;
|
||||
|
||||
// return `value.length` for `arguments` objects, arrays, strings, and DOM
|
||||
// query collections of libraries like jQuery and MooTools
|
||||
// http://code.google.com/p/fbug/source/browse/branches/firebug1.9/content/firebug/chrome/reps.js?r=12614#653
|
||||
// http://trac.webkit.org/browser/trunk/Source/WebCore/inspector/InjectedScriptSource.js?rev=125186#L609
|
||||
if (arrayLikeClasses[className] || (noArgsClass && isArguments(value)) ||
|
||||
(className == objectClass && length > -1 && length === length >>> 0 && isFunction(value.splice))) {
|
||||
return length;
|
||||
}
|
||||
return keys(value).length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array composed of the own enumerable property values of `object`.
|
||||
*
|
||||
@@ -2365,6 +2326,34 @@
|
||||
'inLoop': '!' + filterIteratorOptions.inLoop
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the size of the `collection` by returning `collection.length` for arrays
|
||||
* and array-like objects or the number of own enumerable properties for objects.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collections
|
||||
* @param {Array|Object|String} collection The collection to inspect.
|
||||
* @returns {Number} Returns `collection.length` or number of own enumerable properties.
|
||||
* @example
|
||||
*
|
||||
* _.size([1, 2]);
|
||||
* // => 2
|
||||
*
|
||||
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
|
||||
* // => 3
|
||||
*
|
||||
* _.size('curly');
|
||||
* // => 5
|
||||
*/
|
||||
function size(collection) {
|
||||
if (!collection) {
|
||||
return 0;
|
||||
}
|
||||
var length = collection.length;
|
||||
return length > -1 && length === length >>> 0 ? length : keys(collection).length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the `callback` returns a truthy value for **any** element of a
|
||||
* `collection`. The function returns as soon as it finds passing value, and
|
||||
@@ -3833,8 +3822,8 @@
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utilities
|
||||
* @param {Number} min The minimum possible value
|
||||
* @param {Number} max The maximum possible value
|
||||
* @param {Number} min The minimum possible value.
|
||||
* @param {Number} max The maximum possible value.
|
||||
* @returns {Number} Returns the random number.
|
||||
* @example
|
||||
*
|
||||
|
||||
18
lodash.min.js
vendored
18
lodash.min.js
vendored
@@ -22,7 +22,7 @@ q.push,ht=U.propertyIsEnumerable,pt=q.slice,dt=U.toString,vt=tt.test(vt=pt.bind)
|
||||
,i:"u[i]=A",e:"}}"},tn={j:"[]",i:"c(A,i,d)&&u.push(A)"},nn={q:"if(y)c=k(c,y)"},rn={i:{l:Gt.i}},sn={j:"",f:"if(!d)return[]",d:{b:"u=Array(l)",l:"u="+(zt?"Array(l)":"[]")},i:{b:"u[i]=c(A,i,d)",l:"u"+(zt?"[o]=":".push")+"(c(A,i,d))"}},on={r:i,a:"n,c,y",j:"{}",q:"var S=typeof c=='function';if(!S){var t=e.apply(E,arguments)}else if(y)c=k(c,y)",i:"if(S?!c(A,i,n):N(t,i)<0)u[i]=A"};jt&&(b=function(e){return!!e&&!!lt.call(e,"callee")});var un=gt||function(e){return dt.call(e)==Tt};w(/x/)&&(w=function(e){return"[object Function]"==
|
||||
dt.call(e)}),E(Kt)||(E=function(e,t){var n=i;if(!e||"object"!=typeof e||!t&&b(e))return n;var r=e.constructor;return(!qt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!w(r)||r instanceof r)?Ht?(cn(e,function(t,r){return n=!lt.call(e,r),i}),n===i):(cn(e,function(e,t){n=t}),n===i||lt.call(e,n)):n});var an=a({a:"n",j:"[]",i:"u.push(i)"}),fn=a(en,{i:"if(u[i]==null)"+en.i}),ln=a(en),cn=a(Gt,nn,rn,{r:i}),hn=a(Gt,nn,rn),pn=a({r:i,a:"n",j:"[]",i:"if(T(A))u.push(i)",e:"u.sort()"}),dn=a({a:"n"
|
||||
,j:"{}",i:"u[A]=i"}),vn=a({a:"A",j:"true",q:"var H=z.call(A),l=A.length;if(D[H]"+(jt?"||P(A)":"")+"||(H==X&&l>-1&&l===l>>>0&&T(A.splice)))return!l",i:{l:"return false"}}),mn=bt?function(e){var t=typeof e;return"function"==t&&ht.call(e,"prototype")?an(e):e&&Kt[t]?bt(e):[]}:an,gn=a(en,{a:"n,ee,O,ff",q:"var J,L,Q,gg,dd=O==U;if(!dd)ff=[];for(var a=1,b=dd?2:arguments.length;a<b;a++){if(j=arguments[a]){",i:"if(A&&((Q=R(A))||U(A))){L=false;gg=ff.length;while(gg--)if(L=ff[gg].c==A)break;if(L){u[i]=ff[gg].d}else{J=(J=u[i])&&Q?(R(J)?J:[]):(U(J)?J:{});ff.push({d:J,c:A});u[i]=G(J,A,U,ff)}}else if(A!=null)u[i]=A"
|
||||
}),yn=a(on),bn=a({a:"n",j:"[]",i:"u.push([i,A])"}),wn=a(on,{q:"if(typeof c!='function'){var q,t=e.apply(E,arguments),l=t.length;for(i=1;i<l;i++){q=t[i];if(q in n)u[q]=n[q]}}else{if(y)c=k(c,y)",i:"if(c(A,i,n))u[i]=A",e:"}"}),En=a({a:"n",j:"[]",i:"u.push(A)"}),Sn=a({a:"d,hh",j:"false",o:i,d:{b:"if(z.call(d)==x)return d.indexOf(hh)>-1"},i:"if(A===hh)return true"}),xn=a(Gt,Yt),Tn=a(Gt,Zt),Nn=a(Gt,tn),Cn=a(Gt,nn,{j:"",i:"if(c(A,i,d))return A"}),kn=a(Gt,nn),Ln=a(Gt,Yt,{i:"q=c(A,i,d);(g.call(u,q)?u[q]:u[q]=[]).push(A)"
|
||||
}),yn=a(on),bn=a({a:"n",j:"[]",i:"u"+(zt?"[o]=":".push")+"([i,A])"}),wn=a(on,{q:"if(typeof c!='function'){var q,t=e.apply(E,arguments),l=t.length;for(i=1;i<l;i++){q=t[i];if(q in n)u[q]=n[q]}}else{if(y)c=k(c,y)",i:"if(c(A,i,n))u[i]=A",e:"}"}),En=a({a:"n",j:"[]",i:"u.push(A)"}),Sn=a({a:"d,hh",j:"false",o:i,d:{b:"if(z.call(d)==x)return d.indexOf(hh)>-1"},i:"if(A===hh)return true"}),xn=a(Gt,Yt),Tn=a(Gt,Zt),Nn=a(Gt,tn),Cn=a(Gt,nn,{j:"",i:"if(c(A,i,d))return A"}),kn=a(Gt,nn),Ln=a(Gt,Yt,{i:"q=c(A,i,d);(g.call(u,q)?u[q]:u[q]=[]).push(A)"
|
||||
}),An=a(sn,{a:"d,V",q:"var C=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[i]=(S?V:A[V]).apply(A,C)",l:"u"+(zt?"[o]=":".push")+"((S?V:A[V]).apply(A,C))"}}),On=a(Gt,sn),Mn=a(sn,{a:"d,bb",i:{b:"u[i]=A[bb]",l:"u"+(zt?"[o]=":".push")+"(A[bb])"}}),_n=a({a:"d,c,B,y",j:"B",q:"var W=arguments.length<3;if(y)c=k(c,y)",d:{b:"if(W)u=j[++i]"},i:{b:"u=c(u,A,i,d)",l:"u=W?(W=false,A):c(u,A,i,d)"}}),Dn=a(Gt,tn,{i:"!"+tn.i}),Pn=a(Gt,Zt,{j:"false",i:Zt.i.replace("!","")}),Hn=a(Gt,Yt,sn,{i:{b:"u[i]={a:c(A,i,d),b:i,d:A}"
|
||||
,l:"u"+(zt?"[o]=":".push")+"({a:c(A,i,d),b:i,d:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].d"}),Bn=a(tn,{a:"d,aa",q:"var t=[];K(aa,function(A,q){t.push(q)});var cc=t.length",i:"for(var q,Z=true,s=0;s<cc;s++){q=t[s];if(!(Z=A[q]===aa[q]))break}Z&&u.push(A)"}),jn=a({r:i,s:i,a:"n",j:"n",q:"var M=arguments,l=M.length;if(l>1){for(var i=1;i<l;i++)u[M[i]]=F(u[M[i]],u);return u}",i:"if(T(u[i]))u[i]=F(u[i],u)"});s.VERSION="0.6.1",s.after=function(e,t){return 1>e?t():function(){if(1>--e)return t.apply
|
||||
(this,arguments)}},s.bind=_,s.bindAll=jn,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=S,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++n<r;)e[n]&&t.push(e[n]);return t},s.compose=function(){var e=arguments;return function(){for(var t=arguments,n=e.length;n--;)t=[e[n].apply(this,t)];return t[0]}},s.contains=Sn,s.countBy=xn,s.debounce=function(e,t,n){function i(){a=r,n||e.apply(u,s)}var s,o,u,a;return function(){var r=n&&!a;return s=arguments,u=this,Mt(a),a=_t
|
||||
@@ -31,11 +31,11 @@ dt.call(e)}),E(Kt)||(E=function(e,t){var n=i;if(!e||"object"!=typeof e||!t&&b(e)
|
||||
n||e===i||dt.call(e)==Nt},s.isElement=function(e){return e?1===e.nodeType:i},s.isEmpty=vn,s.isEqual=x,s.isFinite=function(e){return yt(e)&&dt.call(e)==kt},s.isFunction=w,s.isNaN=function(e){return dt.call(e)==kt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e?Kt[typeof e]:i},s.isUndefined=function(e){return e===t},s.keys=mn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:pt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(
|
||||
n&&"number"==typeof n&&(r=(0>n?wt(0,r+n):Et(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=On,s.max=L,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return lt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=gn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s<o;)e[s]<i&&(i=e[s]);return i}for(n&&(t=p(t,n));++s<o;)n=t(e[s],s,e),n<r&&(r=n,i=e[s]);return i},s.mixin=P,s.noConflict=function(){return e
|
||||
._=$,this},s.object=function(e,t){if(!e)return{};for(var n=-1,r=e.length,i={};++n<r;)t?i[e[n]]=t[n]:i[e[n][0]]=e[n][1];return i},s.omit=yn,s.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},s.pairs=bn,s.partial=function(e){var t=pt.call(arguments,1),n=t.length;return function(){var r;return r=arguments,r.length&&(t.length=n,ct.apply(t,r)),r=1==t.length?e.call(this,t[0]):e.apply(this,t),t.length=n,r}},s.pick=wn,s.pluck=Mn,s.random=function(e,t){return arguments
|
||||
.length?(e||(e=0),t||(t=e,e=0),e+mt(St()*(t-e+1))):St()},s.range=function(e,t,n){e=+e||0,n=+n||1,t==r&&(t=e,e=0);for(var i=-1,t=wt(0,Math.ceil((t-e)/n)),s=Array(t);++i<t;)s[i]=e,e+=n;return s},s.reduce=_n,s.reduceRight=T,s.reject=Dn,s.rest=A,s.result=function(e,t){if(!e)return r;var n=e[t];return w(n)?e[t]():n},s.shuffle=function(e){if(!e)return[];for(var t,n=-1,r=e.length,i=Array(r);++n<r;)t=mt(St()*(n+1)),i[n]=i[t],i[t]=e[n];return i},s.size=function(e){if(!e)return 0;var t=dt.call(e),n=e.length
|
||||
;return Xt[t]||jt&&b(e)||t==Lt&&-1<n&&n===n>>>0&&w(e.splice)?n:mn(e).length},s.some=Pn,s.sortBy=Hn,s.sortedIndex=O,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var e=e+"",o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,p=n=n.variable||h.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=H&&(H=a,F=RegExp("<e%-([\\s\\S]+?)%>|<e%=([\\s\\S]+?)%>"+(a?"|"+a.source:""),"g")),o=at.length
|
||||
,e=e.replace(F,m),o=o!=at.length,e="__p += '"+e.replace(it,c).replace(nt,l)+"';",at.length=0,p||(n=B||"obj",o?e="with("+n+"){"+e+"}":(n!=B&&(B=n,j=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(et,"$&"+n+".").replace(j,"$1__d"))),e=(o?e.replace(Q,""):e).replace(G,"$1").replace(Y,"$1;"),e="function("+n+"){"+(p?"":n+"||("+n+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(p?"":",__d="+n+"."+n+"||"+n)+";")+e+"return __p}";try{
|
||||
u=Function("_","return "+e)(s)}catch(d){u=function(){throw d}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=_t(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r<e;)t.call(n,r);else for(;++r<e;)t(r)},s.toArray=function(e){if(!e)return[];if(e.toArray&&w(e.toArray))return e.toArray();var t=e.length;return-1<t&&t===t>>>0?(Ft?dt.call
|
||||
(e)==Ot:"string"==typeof e)?e.split(""):pt.call(e):En(e)},s.unescape=function(e){return e==r?"":(e+"").replace(K,y)},s.union=function(){for(var e=-1,t=[],n=ft.apply(t,arguments),r=n.length;++e<r;)0>k(t,n[e])&&t.push(n[e]);return t},s.uniq=M,s.uniqueId=function(e){var t=X++;return e?e+t:t},s.values=En,s.where=Bn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n<r;)i(e[n])||t.push(e[n]);return t},s.wrap=function(e,t){return function(){var n=[e];return arguments
|
||||
.length&&ct.apply(n,arguments),t.apply(this,n)}},s.zip=function(e){if(!e)return[];for(var t=-1,n=L(Mn(arguments,"length")),r=Array(n);++t<n;)r[t]=Mn(arguments,t);return r},s.all=Tn,s.any=Pn,s.collect=On,s.detect=Cn,s.drop=A,s.each=kn,s.foldl=_n,s.foldr=T,s.head=N,s.include=Sn,s.inject=_n,s.methods=pn,s.select=Nn,s.tail=A,s.take=N,s.unique=M,kn({Date:Ct,Number:kt,RegExp:At,String:Ot},function(e,t){s["is"+t]=function(t){return dt.call(t)==e}}),o.prototype=s.prototype,P(s),o.prototype.chain=function(
|
||||
){return this._chain=n,this},o.prototype.value=function(){return this._wrapped},kn("pop push reverse shift sort splice unshift".split(" "),function(e){var t=q[e];o.prototype[e]=function(){var e=this._wrapped;return t.apply(e,arguments),Pt&&e.length===0&&delete e[0],this._chain&&(e=new o(e),e._chain=n),e}}),kn(["concat","join","slice"],function(e){var t=q[e];o.prototype[e]=function(){var e=t.apply(this._wrapped,arguments);return this._chain&&(e=new o(e),e._chain=n),e}}),typeof define=="function"&&typeof
|
||||
define.amd=="object"&&define.amd?(e._=s,define(function(){return s})):I?"object"==typeof module&&module&&module.t==I?(module.t=s)._=s:I._=s:e._=s})(this);
|
||||
.length?(e||(e=0),t||(t=e,e=0),e+mt(St()*(t-e+1))):St()},s.range=function(e,t,n){e=+e||0,n=+n||1,t==r&&(t=e,e=0);for(var i=-1,t=wt(0,Math.ceil((t-e)/n)),s=Array(t);++i<t;)s[i]=e,e+=n;return s},s.reduce=_n,s.reduceRight=T,s.reject=Dn,s.rest=A,s.result=function(e,t){if(!e)return r;var n=e[t];return w(n)?e[t]():n},s.shuffle=function(e){if(!e)return[];for(var t,n=-1,r=e.length,i=Array(r);++n<r;)t=mt(St()*(n+1)),i[n]=i[t],i[t]=e[n];return i},s.size=function(e){if(!e)return 0;var t=e.length;return-1<t&&
|
||||
t===t>>>0?t:mn(e).length},s.some=Pn,s.sortBy=Hn,s.sortedIndex=O,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var e=e+"",o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,p=n=n.variable||h.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=H&&(H=a,F=RegExp("<e%-([\\s\\S]+?)%>|<e%=([\\s\\S]+?)%>"+(a?"|"+a.source:""),"g")),o=at.length,e=e.replace(F,m),o=o!=at.length,e="__p += '"+e.replace
|
||||
(it,c).replace(nt,l)+"';",at.length=0,p||(n=B||"obj",o?e="with("+n+"){"+e+"}":(n!=B&&(B=n,j=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(et,"$&"+n+".").replace(j,"$1__d"))),e=(o?e.replace(Q,""):e).replace(G,"$1").replace(Y,"$1;"),e="function("+n+"){"+(p?"":n+"||("+n+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(p?"":",__d="+n+"."+n+"||"+n)+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(d){u=function(){throw d
|
||||
}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=_t(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r<e;)t.call(n,r);else for(;++r<e;)t(r)},s.toArray=function(e){if(!e)return[];if(e.toArray&&w(e.toArray))return e.toArray();var t=e.length;return-1<t&&t===t>>>0?(Ft?dt.call(e)==Ot:"string"==typeof e)?e.split(""):pt.call(e):En(e)}
|
||||
,s.unescape=function(e){return e==r?"":(e+"").replace(K,y)},s.union=function(){for(var e=-1,t=[],n=ft.apply(t,arguments),r=n.length;++e<r;)0>k(t,n[e])&&t.push(n[e]);return t},s.uniq=M,s.uniqueId=function(e){var t=X++;return e?e+t:t},s.values=En,s.where=Bn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n<r;)i(e[n])||t.push(e[n]);return t},s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&ct.apply(n,arguments),t.apply(this,n)}},s.
|
||||
zip=function(e){if(!e)return[];for(var t=-1,n=L(Mn(arguments,"length")),r=Array(n);++t<n;)r[t]=Mn(arguments,t);return r},s.all=Tn,s.any=Pn,s.collect=On,s.detect=Cn,s.drop=A,s.each=kn,s.foldl=_n,s.foldr=T,s.head=N,s.include=Sn,s.inject=_n,s.methods=pn,s.select=Nn,s.tail=A,s.take=N,s.unique=M,kn({Date:Ct,Number:kt,RegExp:At,String:Ot},function(e,t){s["is"+t]=function(t){return dt.call(t)==e}}),o.prototype=s.prototype,P(s),o.prototype.chain=function(){return this._chain=n,this},o.prototype.value=function(
|
||||
){return this._wrapped},kn("pop push reverse shift sort splice unshift".split(" "),function(e){var t=q[e];o.prototype[e]=function(){var e=this._wrapped;return t.apply(e,arguments),Pt&&e.length===0&&delete e[0],this._chain&&(e=new o(e),e._chain=n),e}}),kn(["concat","join","slice"],function(e){var t=q[e];o.prototype[e]=function(){var e=t.apply(this._wrapped,arguments);return this._chain&&(e=new o(e),e._chain=n),e}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(e._=s,define(function(
|
||||
){return s})):I?"object"==typeof module&&module&&module.t==I?(module.t=s)._=s:I._=s:e._=s})(this);
|
||||
@@ -1304,10 +1304,6 @@
|
||||
})
|
||||
});
|
||||
|
||||
test('should work with an object that has a `length` property', function() {
|
||||
equal(_.size({ 'length': 3 }), 1);
|
||||
});
|
||||
|
||||
test('should work with jQuery/MooTools DOM query collections', function() {
|
||||
function Foo(elements) { Array.prototype.push.apply(this, elements); }
|
||||
Foo.prototype = { 'length': 0, 'splice': Array.prototype.splice };
|
||||
|
||||
Reference in New Issue
Block a user