From 2543afebf1c1be6e4669226f665e86ccffd4a9c0 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 2 Feb 2014 19:05:34 -0800 Subject: [PATCH] Optimize `_.invoke` for arrays. --- dist/lodash.compat.js | 17 +++- dist/lodash.compat.min.js | 26 ++--- dist/lodash.js | 17 +++- dist/lodash.min.js | 61 ++++++------ dist/lodash.underscore.js | 17 +++- dist/lodash.underscore.min.js | 70 ++++++------- doc/README.md | 178 +++++++++++++++++----------------- lodash.js | 17 +++- perf/perf.js | 22 +++-- 9 files changed, 232 insertions(+), 193 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 782622b9f..b7a761fe0 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -3859,15 +3859,22 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var args = slice(arguments, 2), - index = -1, + var index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); - }); + if (arguments.length < 3 && isArray(collection)) { + while (++index < length) { + var value = collection[index]; + result[index] = isFunc ? methodName.call(value) : value[methodName](); + } + } else { + var args = slice(arguments, 2); + baseEach(collection, function(value) { + result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + }); + } return result; } diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 9c51d5875..ff0c0b28f 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -45,19 +45,19 @@ n[u]=Ot(n[u],j,null,n)}return n},u.bindKey=function(n,t){return 3>arguments.leng }},u.countBy=he,u.create=function(n,t){var r=A(n);return t?tr(r,t):r},u.createCallback=cr,u.curry=function(n,t){return typeof t!="number"&&(t=+t||(n?n.length:0)),Ot(n,C,t)},u.debounce=nr,u.defaults=rr,u.defer=function(n){if(!or(n))throw new kr;var t=qt(arguments,1);return Kr(function(){n.apply(w,t)},1)},u.delay=function(n,t){if(!or(n))throw new kr;var r=qt(arguments,2);return Kr(function(){n.apply(w,r)},t)},u.difference=function(n){return gt(n,mt(arguments,true,true,1))},u.filter=Kt,u.flatten=function(n,t,r,e){var u=typeof t; return"boolean"!=u&&null!=t&&(e=r,r=t,t=false,"number"!=u&&"string"!=u||!e||e[r]!==n||(r=null)),null!=r&&(n=Xt(n,r,e)),mt(n,t)},u.forEach=Ut,u.forEachRight=Vt,u.forIn=function(n,t,r){return t=t&&typeof r=="undefined"?t:H(t,r,3),se(n,t)},u.forInRight=function(n,t,r){var e=[];se(n,function(n,t){e.push(t,n)});var u=e.length;for(t=H(t,r,3);u--&&false!==t(e[u--],e[u],n););return n},u.forOwn=function(n,t,r){return t=t&&typeof r=="undefined"?t:H(t,r,3),dt(n,t)},u.forOwnRight=function(n,t,r){var e=_e(n),u=e.length; for(t=H(t,r,3);u--&&(r=e[u],false!==t(n[r],r,n)););return n},u.functions=er,u.groupBy=ve,u.indexBy=ye,u.initial=function(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o;for(t=u.createCallback(t,r,3);a--&&t(n[a],a,n);)e++}else e=null==t||r?1:t||e;return e=o-e,qt(n,0,0=S&&ce(e?n[e]:l)))}var i=n[0],p=-1,g=i?i.length:0,h=[]; -n:for(;++p(v?r(v,f):a(l,f))){for(e=u,(v||l).push(f);--e;)if(v=o[e],0>(v?r(v,f):a(n[e],f)))continue n;h.push(f)}}return s(o),s(l),h},u.invert=function(n,t){for(var r=-1,e=_e(n),u=e.length,o={};++rr?Zr(0,e+r):ne(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=gr,u.noConflict=function(){return n._=Nr,this},u.noop=hr,u.now=Ce,u.parseInt=ke,u.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ee(),ne(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):xt(n,t) +n:for(;++p(v?r(v,f):a(l,f))){for(e=u,(v||l).push(f);--e;)if(v=o[e],0>(v?r(v,f):a(n[e],f)))continue n;h.push(f)}}return s(o),s(l),h},u.invert=function(n,t){for(var r=-1,e=_e(n),u=e.length,o={};++rarguments.length&&de(n))for(;++rr?Zr(0,e+r):ne(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=gr,u.noConflict=function(){return n._=Nr,this},u.noop=hr,u.now=Ce,u.parseInt=ke,u.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ee(),ne(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):xt(n,t) },u.reduce=Ht,u.reduceRight=Jt,u.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,or(r)?n[t]():r)},u.runInContext=_,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:_e(n).length},u.some=Yt,u.sortedIndex=Ft,u.template=function(n,t,r){var e=u.templateSettings;n=Cr(n||""),r=rr({},r,e);var o,a=rr({},r.imports,e.imports),e=_e(a),a=fr(a),i=0,l=r.interpolate||U,c="__p+='",l=xr((r.escape||U).source+"|"+l.source+"|"+(l===D?W:U).source+"|"+(r.evaluate||U).source+"|$","g"); n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(X,f),r&&(c+="'+__e("+r+")+'"),a&&(o=true,c+="';"+a+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t}),c+="';",l=r=r.variable,l||(r="obj",c="with("+r+"){"+c+"}"),c=(o?c.replace(T,""):c).replace(P,"$1").replace(q,"$1;"),c="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=br(e,"return "+c).apply(w,a) }catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},u.trim=we,u.trimLeft=je,u.trimRight=xe,u.unescape=function(n){return null==n?"":(n=Cr(n),0>n.indexOf(";")?n:n.replace(F,b))},u.uniqueId=function(n){var t=++R;return Cr(null==n?"":n)+t},u.all=zt,u.any=Yt,u.detect=Mt,u.findWhere=Mt,u.foldl=Ht,u.foldr=Jt,u.include=Wt,u.inject=Ht,gr(function(){var n={};return dt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Rt,u.last=function(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o; diff --git a/dist/lodash.js b/dist/lodash.js index 313a50a5b..3465a44ed 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -3596,15 +3596,22 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var args = slice(arguments, 2), - index = -1, + var index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); - }); + if (arguments.length < 3 && typeof length == 'number') { + while (++index < length) { + var value = collection[index]; + result[index] = isFunc ? methodName.call(value) : value[methodName](); + } + } else { + var args = slice(arguments, 2); + baseEach(collection, function(value) { + result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + }); + } return result; } diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 7f828d5f0..97bade34d 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -9,15 +9,15 @@ */ (function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202e||13e||8202r||13r||8202=A&&(o=r,e=ie(e));++uo(e,f)&&a.push(f)}return a}function ht(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++r=A&&(o=r,e=ie(e));++uo(e,f)&&a.push(f)}return a}function ht(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++r=A,l=[];if(f)var s=ie(),i=r;else s=u?c():l;for(;++oi(s,h))&&((u||f)&&s.push(h),l.push(g)) }return!f&&u&&p(s),l}function xt(n){return function(t,r,e){var u={};r=y.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++er&&(r=0),e=[n,t,r,e,u,o],t==w||t==(w|C)?S(e):pt(e)) }function Ot(){var n=(n=y.indexOf)===Rt?t:n;return n}function At(n){return typeof n=="function"&&Nr.test(Fr.call(n))}function St(n){var t,r;return n&&Er.call(n)==et&&(Br.call(n,"constructor")||(t=n.constructor,!er(t)||t instanceof t))?(o(n,function(n,t){r=t}),typeof r=="undefined"||Br.call(n,r)):false}function Et(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Er.call(n)==Q||false}function Nt(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=-1;for(t=y.createCallback(t,r,3);++oo&&(o=a) }else t=null==t&&ir(n)?e:y.createCallback(t,r,3),ht(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Xt(n,t,r,e){var u=3>arguments.length;t=y.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=y.createCallback(t,e,4),vt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Ht(n){var t=-1,r=n?n.length:0,e=hr(typeof r=="number"?r:0); -return ht(n,function(n){var r=kt(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;t=y.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++rarguments.length)return Ct(n,w,null,t);var r=n&&(n[N]?n[N][2]:n.length),e=Tt(arguments,2),r=r-e.length;return Ct(n,w|C,r,t,e)}function Yt(n,t,r){function e(){c&&Ir(c),i=c=p=_,(h||g!==t)&&(s=de(),a=n.apply(l,o),c||i||(o=l=null))}function u(){var r=t-(de()-f); -0=y;m?(i&&(i=Ir(i)),s=f,a=n.apply(l,o)):i||(i=Wr(e,y))}return m&&c?c=Ir(c):c||t===g||(c=Wr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a +return ht(n,function(n){var r=kt(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;t=y.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++rarguments.length)return Ct(n,w,null,t);var r=n&&(n[N]?n[N][2]:n.length),e=Tt(arguments,2),r=r-e.length;return Ct(n,w|C,r,t,e)}function Yt(n,t,r){function e(){c&&Ir(c),i=c=p=_,(h||g!==t)&&(s=be(),a=n.apply(l,o),c||i||(o=l=null))}function u(){var r=t-(be()-f); +0=y;m?(i&&(i=Ir(i)),s=f,a=n.apply(l,o)):i||(i=Wr(e,y))}return m&&c?c=Ir(c):c||t===g||(c=Wr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a }}function Zt(n,t,r){var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3--n?t.apply(this,arguments):void 0}},y.assign=Zt,y.at=function(n,t){var r=arguments,e=-1,u=mt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=hr(o);++e--n?t.apply(this,arguments):void 0}},y.assign=Zt,y.at=function(n,t){var r=arguments,e=-1,u=mt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=hr(o);++earguments.length?Ct(t,w|k,null,n):Ct(t,w|k|C,null,n,Tt(arguments,2))},y.chain=function(n){return n=new m(n),n.__chain__=true,n},y.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t=A&&ie(e?n[e]:f)))}var a=n[0],s=-1,g=a?a.length:0,h=[]; -n:for(;++s(v?r(v,l):i(f,l))){for(e=u,(v||f).push(l);--e;)if(v=o[e],0>(v?r(v,l):i(n[e],l)))continue n;h.push(l)}}return p(o),p(f),h},y.invert=function(n,t){for(var r=-1,e=he(n),u=e.length,o={};++rr?Hr(0,e+r):Jr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},y.mixin=pr,y.noConflict=function(){return n._=Sr,this},y.noop=sr,y.now=de,y.parseInt=be,y.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Zr(),Jr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):kt(n,t)},y.reduce=Xt,y.reduceRight=Gt,y.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,er(r)?n[t]():r) -},y.runInContext=b,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:he(n).length},y.some=Jt,y.sortedIndex=Ft,y.template=function(n,t,r){var e=y.templateSettings;n=kr(n||""),r=nr({},r,e);var u,o=nr({},r.imports,e.imports),e=he(o),o=ar(o),i=0,a=r.interpolate||M,f="__p+='",a=wr((r.escape||M).source+"|"+a.source+"|"+(a===W?z:M).source+"|"+(r.evaluate||M).source+"|$","g");n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(V,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t -}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(I,""):f).replace(T,"$1").replace(F,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=mr(e,"return "+f).apply(_,o)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.trim=ve,y.trimLeft=ye,y.trimRight=me,y.unescape=function(n){return null==n?"":(n=kr(n),0>n.indexOf(";")?n:n.replace($,d)) -},y.uniqueId=function(n){var t=++R;return kr(null==n?"":n)+t},y.all=zt,y.any=Jt,y.detect=Pt,y.findWhere=Pt,y.foldl=Xt,y.foldr=Gt,y.include=Wt,y.inject=Xt,pr(function(){var n={};return dt(y,function(t,r){y.prototype[r]||(n[r]=t)}),n}(),false),y.first=Nt,y.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=y.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:_;return e=u-e,Tt(n,0"']/g,D=/<%-([\s\S]+?)%>/g,q=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,z=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,P=/^\s*function[ \n\r\t]+\w/,K=/^0[xX]/,M=/($^)/,U=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,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",G=[],H=[],J="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Q="[object Arguments]",Y="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Function]",rt="[object Number]",et="[object Object]",ut="[object RegExp]",ot="[object String]",it={}; +n:for(;++s(v?r(v,l):i(f,l))){for(e=u,(v||f).push(l);--e;)if(v=o[e],0>(v?r(v,l):i(n[e],l)))continue n;h.push(l)}}return p(o),p(f),h},y.invert=function(n,t){for(var r=-1,e=he(n),u=e.length,o={};++rarguments.length&&typeof u=="number")for(;++rr?Hr(0,e+r):Jr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},y.mixin=pr,y.noConflict=function(){return n._=Sr,this},y.noop=sr,y.now=be,y.parseInt=de,y.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Zr(),Jr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):kt(n,t) +},y.reduce=Xt,y.reduceRight=Gt,y.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,er(r)?n[t]():r)},y.runInContext=d,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:he(n).length},y.some=Jt,y.sortedIndex=Ft,y.template=function(n,t,r){var e=y.templateSettings;n=kr(n||""),r=nr({},r,e);var u,o=nr({},r.imports,e.imports),e=he(o),o=ar(o),i=0,a=r.interpolate||M,f="__p+='",a=wr((r.escape||M).source+"|"+a.source+"|"+(a===W?z:M).source+"|"+(r.evaluate||M).source+"|$","g"); +n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(V,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(I,""):f).replace(T,"$1").replace(F,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=mr(e,"return "+f).apply(_,o) +}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.trim=ve,y.trimLeft=ye,y.trimRight=me,y.unescape=function(n){return null==n?"":(n=kr(n),0>n.indexOf(";")?n:n.replace($,b))},y.uniqueId=function(n){var t=++R;return kr(null==n?"":n)+t},y.all=zt,y.any=Jt,y.detect=Pt,y.findWhere=Pt,y.foldl=Xt,y.foldr=Gt,y.include=Wt,y.inject=Xt,pr(function(){var n={};return bt(y,function(t,r){y.prototype[r]||(n[r]=t)}),n}(),false),y.first=Nt,y.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u; +for(t=y.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:_;return e=u-e,Tt(n,0"']/g,D=/<%-([\s\S]+?)%>/g,q=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,z=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,P=/^\s*function[ \n\r\t]+\w/,K=/^0[xX]/,M=/($^)/,U=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,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",G=[],H=[],J="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Q="[object Arguments]",Y="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Function]",rt="[object Number]",et="[object Object]",ut="[object RegExp]",ot="[object String]",it={}; it[tt]=false,it[Q]=it[Y]=it[Z]=it[nt]=it[rt]=it[et]=it[ut]=it[ot]=true;var at={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},lt={"&":"&","<":"<",">":">",'"':""","'":"'"},ct={"&":"&","<":"<",">":">",""":'"',"'":"'"},pt={"function":true,object:true},st={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},gt=pt[typeof window]&&window||this,ht=pt[typeof exports]&&exports&&!exports.nodeType&&exports,pt=pt[typeof module]&&module&&!module.nodeType&&module,vt=ht&&pt&&typeof global=="object"&&global; -!vt||vt.global!==vt&&vt.window!==vt&&vt.self!==vt||(gt=vt);var vt=pt&&pt.exports===ht&&ht,yt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(gt._=yt, define(function(){return yt})):ht&&pt?vt?(pt.exports=yt)._=yt:ht._=yt:gt._=yt}).call(this); \ No newline at end of file +!vt||vt.global!==vt&&vt.window!==vt&&vt.self!==vt||(gt=vt);var vt=pt&&pt.exports===ht&&ht,yt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(gt._=yt, define(function(){return yt})):ht&&pt?vt?(pt.exports=yt)._=yt:ht._=yt:gt._=yt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index c7dc35157..66e0bb49c 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -2481,15 +2481,22 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var args = slice(arguments, 2), - index = -1, + var index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); - }); + if (arguments.length < 3 && typeof length == 'number') { + while (++index < length) { + var value = collection[index]; + result[index] = isFunc ? methodName.call(value) : value[methodName](); + } + } else { + var args = slice(arguments, 2); + baseEach(collection, function(value) { + result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + }); + } return result; } diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 605c55e7a..7d28da74b 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,38 +3,38 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ -;(function(){function n(n){var r=[];if(!L(n))return r;for(var t in n)Ur.call(n,t)&&r.push(t);return r}function r(n,r){if(L(n))for(var t in n)if(r(n[t],t,n)===sr)break}function t(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function h(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++tu(f,l))&&(t&&f.push(l),i.push(a))}return i}function _(n){return function(r,t,e){var u={};t=Z(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++et&&(t=0),n=[n,r,t,e,u,o],r==or||r==(or|lr)?l(n):s(n)}function w(){var n=(n=f.indexOf)===A?t:n;return n}function j(n){return typeof n=="function"&&Wr.test(Pr.call(n))}function x(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Dr.call(n)==br||false}function T(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=-1;for(r=Z(r,t,3);++oe?Yr(0,u+e):e||0;else if(e)return e=k(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function E(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=Z(r,t,3);++ur?r=Yr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Yr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=Z(r,t,3),h(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function M(n,r,t,e){var u=3>arguments.length;r=Z(r,e,4);var o=-1,i=n?n.length:0; -if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=Z(r,e,4),v(n,function(n,e,o){t=u?(u=false,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 h(n,function(n){var t;t=++r,t=0+Cr(rt()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=Z(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++targuments.length)return d(n,or,null,r);var t=n&&(n[pr]?n[pr][2]:n.length),e=O(arguments,2),t=t-e.length;return d(n,or|lr,t,r,e)}function U(n,r,t){function e(){c&&clearTimeout(c),i=c=p=ur,(h||g!==r)&&(s=lt(),f=n.apply(l,o),c||i||(o=l=null))}function u(){var t=r-(lt()-a);0=y;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(l,o)):i||(i=setTimeout(e,y))}return m&&c?c=clearTimeout(c):c||r===g||(c=setTimeout(u,r)),t&&(m=true,f=n.apply(l,o)),!m||c||i||(o=l=null),f}}function V(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,yr=/($^)/,mr=/['\n\r\t\u2028\u2029\\]/g,br="[object Arguments]",_r="[object Array]",dr="[object Boolean]",wr="[object Date]",jr="[object Number]",xr="[object Object]",Tr="[object RegExp]",Ar="[object String]",Er={"&":"&","<":"<",">":">",'"':""","'":"'"},Or={"&":"&","<":"<",">":">",""":'"',"'":"'"},kr={"function":true,object:true},Sr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Nr=kr[typeof window]&&window||this,qr=kr[typeof exports]&&exports&&!exports.nodeType&&exports,Fr=kr[typeof module]&&module&&!module.nodeType&&module,Br=qr&&Fr&&typeof global=="object"&&global; -!Br||Br.global!==Br&&Br.window!==Br&&Br.self!==Br||(Nr=Br);var Rr=Fr&&Fr.exports===qr&&qr,$r=Array.prototype,Ir=Object.prototype,Mr=Nr._,Dr=Ir.toString,Wr=RegExp("^"+(Dr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),zr=Math.ceil,Cr=Math.floor,Pr=Function.prototype.toString,Ur=Ir.hasOwnProperty,Vr=$r.push,Gr=Ir.propertyIsEnumerable,Hr=$r.splice,Jr=j(Jr=Object.create)&&Jr,Kr=j(Kr=Array.isArray)&&Kr,Lr=Nr.isFinite,Qr=Nr.isNaN,Xr=j(Xr=Object.keys)&&Xr,Yr=Math.max,Zr=Math.min,nt=j(nt=Date.now)&&nt,rt=Math.random; -a.prototype=f.prototype;var tt={};!function(){var n={0:1,length:1};tt.spliceObjects=(Hr.call(n,0,1),!n[0])}(1),f.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Jr||(c=function(){function n(){}return function(r){if(L(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Nr.Object()}}()),x(arguments)||(x=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ur.call(n,"callee")&&!Gr.call(n,"callee")||false});var et=_(function(n,r,t){Ur.call(n,t)?n[t]++:n[t]=1 -}),ut=_(function(n,r,t){Ur.call(n,t)?n[t].push(r):n[t]=[r]}),ot=_(function(n,r,t){n[t]=r}),it=$,ft=Kr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Dr.call(n)==_r||false};K(/x/)&&(K=function(n){return typeof n=="function"&&"[object Function]"==Dr.call(n)});var at=Xr?function(n){return L(n)?Xr(n):[]}:n,lt=nt||function(){return(new Date).getTime()};f.after=function(n,r){if(!K(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},f.bind=P,f.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},f.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++rr?0:r);++nt?Yr(0,e+t):Zr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},f.mixin=tr,f.noConflict=function(){return Nr._=Mr,this},f.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Cr(rt()*(r-n+1))},f.reduce=M,f.reduceRight=D,f.result=function(n,r){if(null!=n){var t=n[r]; -return K(t)?n[r]():t}},f.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:at(n).length},f.some=z,f.sortedIndex=k,f.template=function(n,r,t){var e=f,u=e.templateSettings;n=(n||"")+"",t=G({},t,u);var i=0,a="__p+='",u=t.variable;n.replace(RegExp((t.escape||yr).source+"|"+(t.interpolate||yr).source+"|"+(t.evaluate||yr).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(mr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r -}),a+="';",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var l=Function("_","return "+a)(e)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},f.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(hr,i))},f.uniqueId=function(n){var r=++gr+"";return n?n+r:r},f.all=q,f.any=z,f.detect=B,f.findWhere=function(n,r){return C(n,r,true)},f.foldl=M,f.foldr=D,f.include=N,f.inject=M,f.first=T,f.last=function(n,r,t){var e=0,u=n?n.length:0; -if(typeof r!="number"&&null!=r){var o=u;for(r=Z(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:ur;return e=u-e,O(n,0e||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function s(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++tu(f,l))&&(t&&f.push(l),i.push(a))}return i}function m(n){return function(r,t,e){var u={};t=X(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++et&&(t=0),n=[n,r,t,e,u,o],r==er||r==(er|fr)?f(n):c(n)}function _(){var r=(r=o.indexOf)===x?n:r;return r}function d(n){return typeof n=="function"&&Mr.test(zr.call(n))}function w(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ir.call(n)==yr||false}function j(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=-1;for(r=X(r,t,3);++oe?Qr(0,u+e):e||0;else if(e)return e=E(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function T(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=X(r,t,3);++ur?r=Qr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Qr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=X(r,t,3),s(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function $(n,r,t,e){var u=3>arguments.length;r=X(r,e,4);var o=-1,i=n?n.length:0; +if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=X(r,e,4),g(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function M(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return s(n,function(n){var t;t=++r,t=0+Wr(Zr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function D(n,r,t){var e;r=X(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++targuments.length)return b(n,er,null,r);var t=n&&(n[lr]?n[lr][2]:n.length),e=A(arguments,2),t=t-e.length;return b(n,er|fr,t,r,e)}function C(n,r,t){var e,u,o,i,f,a,l,c=0,p=false,s=true;if(!H(n))throw new TypeError;if(r=Qr(0,r)||0,true===t)var g=true,s=false;else J(t)&&(g=t.leading,p="maxWait"in t&&(Qr(r,t.maxWait)||0),s="trailing"in t?t.trailing:s);var v=function(){var t=r-(lt()-i);0=y;m?(u&&(u=clearTimeout(u)),c=i,o=n.apply(f,e)):u||(u=setTimeout(h,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(v,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o}}function P(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,vr=/($^)/,hr=/['\n\r\t\u2028\u2029\\]/g,yr="[object Arguments]",mr="[object Array]",br="[object Boolean]",_r="[object Date]",dr="[object Number]",wr="[object Object]",jr="[object RegExp]",xr="[object String]",Tr={"&":"&","<":"<",">":">",'"':""","'":"'"},Ar={"&":"&","<":"<",">":">",""":'"',"'":"'"},Er={"function":true,object:true},Or={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Sr=Er[typeof window]&&window||this,kr=Er[typeof exports]&&exports&&!exports.nodeType&&exports,Nr=Er[typeof module]&&module&&!module.nodeType&&module,qr=kr&&Nr&&typeof global=="object"&&global; +!qr||qr.global!==qr&&qr.window!==qr&&qr.self!==qr||(Sr=qr);var Fr=Nr&&Nr.exports===kr&&kr,Br=Array.prototype,Rr=Object.prototype,$r=Sr._,Ir=Rr.toString,Mr=RegExp("^"+(Ir+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Dr=Math.ceil,Wr=Math.floor,zr=Function.prototype.toString,Cr=Rr.hasOwnProperty,Pr=Br.push,Ur=Rr.propertyIsEnumerable,Vr=Br.splice,Gr=d(Gr=Object.create)&&Gr,Hr=d(Hr=Array.isArray)&&Hr,Jr=Sr.isFinite,Kr=Sr.isNaN,Lr=d(Lr=Object.keys)&&Lr,Qr=Math.max,Xr=Math.min,Yr=d(Yr=Date.now)&&Yr,Zr=Math.random; +i.prototype=o.prototype;var nt={};!function(){var n={0:1,length:1};nt.spliceObjects=(Vr.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Gr||(a=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Sr.Object()}}()),w(arguments)||(w=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Cr.call(n,"callee")&&!Ur.call(n,"callee")||false});var rt=function(n,r){if(!J(n))return n; +for(var t in n)if(r(n[t],t,n)===cr)break;return n},tt=function(n){var r=[];if(!J(n))return r;for(var t in n)Cr.call(n,t)&&r.push(t);return r},et=m(function(n,r,t){Cr.call(n,t)?n[t]++:n[t]=1}),ut=m(function(n,r,t){Cr.call(n,t)?n[t].push(r):n[t]=[r]}),ot=m(function(n,r,t){n[t]=r}),it=B,ft=Hr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ir.call(n)==mr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Ir.call(n)});var at=Lr?function(n){return J(n)?Lr(n):[] +}:tt,lt=Yr||function(){return(new Date).getTime()};o.after=function(n,r){if(!H(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=z,o.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++rarguments.length&&typeof u=="number")for(;++tr?0:r);++nt?Qr(0,e+t):Xr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=nr,o.noConflict=function(){return Sr._=$r,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+Wr(Zr()*(r-n+1)) +},o.reduce=$,o.reduceRight=I,o.result=function(n,r){if(null!=n){var t=n[r];return H(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:at(n).length},o.some=D,o.sortedIndex=E,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(n||"")+"",t=U({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||vr).source+"|"+(t.interpolate||vr).source+"|"+(t.evaluate||vr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(hr,e),t&&(a+="'+_.escape("+t+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r +}),a+="';",i||(i="obj",a="with("+i+"||{}){"+a+"}"),a="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var l=Function("_","return "+a)(u)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(sr,u))},o.uniqueId=function(n){var r=++pr+"";return n?n+r:r},o.all=k,o.any=D,o.detect=q,o.findWhere=function(n,r){return W(n,r,true)},o.foldl=$,o.foldr=I,o.include=S,o.inject=$,o.first=j,o.last=function(n,r,t){var e=0,u=n?n.length:0; +if(typeof r!="number"&&null!=r){var o=u;for(r=X(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:tr;return e=u-e,A(n,0 ### `_.map(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3936 "View in source") [Ⓣ][1] Creates an array of values by running each element in the collection through the callback. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1810,7 +1810,7 @@ _.map(characters, 'name'); ### `_.max(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3987 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3994 "View in source") [Ⓣ][1] Retrieves the maximum value of a collection. If the collection is empty or falsey `-Infinity` is returned. If a callback is provided it will be executed for each value in the collection to generate the criterion by which the value is ranked. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. @@ -1852,7 +1852,7 @@ _.max(characters, 'age'); ### `_.min(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4063 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4070 "View in source") [Ⓣ][1] Retrieves the minimum value of a collection. If the collection is empty or falsey `Infinity` is returned. If a callback is provided it will be executed for each value in the collection to generate the criterion by which the value is ranked. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. @@ -1894,7 +1894,7 @@ _.min(characters, 'age'); ### `_.pluck(collection, key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4119 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4126 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the collection. @@ -1924,7 +1924,7 @@ _.pluck(characters, 'name'); ### `_.reduce(collection, [callback=identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4151 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4158 "View in source") [Ⓣ][1] Reduces a collection to a value which is the accumulated result of running each element in the collection through the callback, where each successive callback execution consumes the return value of the previous execution. If `accumulator` is not provided the first element of the collection will be used as the initial `accumulator` value. The callback is bound to `thisArg` and invoked with four arguments; *(accumulator, value, index|key, collection)*. @@ -1962,7 +1962,7 @@ var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) { ### `_.reduceRight(collection, [callback=identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4194 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4201 "View in source") [Ⓣ][1] This method is like `_.reduce` except that it iterates over elements of a `collection` from right to left. @@ -1993,7 +1993,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4244 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4251 "View in source") [Ⓣ][1] The opposite of `_.filter`; this method returns the elements of a collection that the callback does **not** return truey for. @@ -2036,7 +2036,7 @@ _.reject(characters, { 'age': 36 }); ### `_.sample(collection, [n])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4270 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4277 "View in source") [Ⓣ][1] Retrieves a random element or `n` random elements from a collection. @@ -2064,7 +2064,7 @@ _.sample([1, 2, 3, 4], 2); ### `_.shuffle(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4298 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4305 "View in source") [Ⓣ][1] Creates an array of shuffled values, using a version of the Fisher-Yates shuffle. See [Wikipedia](http://en.wikipedia.org/wiki/Fisher-Yates_shuffle) for more details. @@ -2088,7 +2088,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4332 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4339 "View in source") [Ⓣ][1] 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. @@ -2118,7 +2118,7 @@ _.size('pebbles'); ### `_.some(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4379 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4386 "View in source") [Ⓣ][1] Checks if the callback returns a truey value for **any** element of a collection. The function returns as soon as it finds a passing value and does not iterate over the entire collection. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2164,7 +2164,7 @@ _.some(characters, { 'age': 1 }); ### `_.sortBy(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4449 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4456 "View in source") [Ⓣ][1] Creates an array of elements, sorted in ascending order by the results of running each element in a collection through the callback. This method performs a stable sort, that is, it will preserve the original sort order of equal elements. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2214,7 +2214,7 @@ _.map(_.sortBy(characters, ['name', 'age']), _.values); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4498 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4505 "View in source") [Ⓣ][1] Converts the `collection` to an array. @@ -2238,7 +2238,7 @@ Converts the `collection` to an array. ### `_.where(collection, props)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4532 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4539 "View in source") [Ⓣ][1] Performs a deep comparison between each element in `collection` and the `props` object, returning an array of all elements that have equivalent property values. @@ -2278,7 +2278,7 @@ _.where(characters, { 'pets': ['dino'] }); ### `_.after(n, func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4560 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4567 "View in source") [Ⓣ][1] Creates a function that executes `func`, with the `this` binding and arguments of the created function, only after being called `n` times. @@ -2311,7 +2311,7 @@ _.forEach(saves, function(type) { ### `_.bind(func, [thisArg], [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4596 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4603 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those provided to the bound function. @@ -2344,7 +2344,7 @@ func(); ### `_.bindAll(object, [methodName])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4640 "View in source") [Ⓣ][1] Binds methods of an object to the object itself, overwriting the existing method. Method names may be specified as individual arguments or as arrays of method names. If no method names are provided all the function properties of `object` will be bound. @@ -2377,7 +2377,7 @@ jQuery('#docs').on('click', view.onClick); ### `_.bindKey(object, key, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4680 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4687 "View in source") [Ⓣ][1] Creates a function that, when called, invokes the method at `object[key]` and prepends any additional `bindKey` arguments to those provided to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern) for more details. @@ -2418,7 +2418,7 @@ func(); ### `_.compose([func])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4716 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4723 "View in source") [Ⓣ][1] Creates a function that is the composition of the provided functions, where each function consumes the return value of the function that follows. For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. Each function is executed with the `this` binding of the composed function. @@ -2456,7 +2456,7 @@ welcome('pebbles'); ### `_.curry(func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4767 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4774 "View in source") [Ⓣ][1] Creates a function which accepts one or more arguments of `func` that when invoked either executes `func` returning its result, if all `func` arguments have been provided, or returns a function that accepts one or more of the remaining `func` arguments, and so on. The arity of `func` can be specified if `func.length` is not sufficient. @@ -2493,7 +2493,7 @@ curried(1, 2, 3); ### `_.debounce(func, wait, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4813 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4820 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Provide an options object to indicate that `func` should be invoked on the leading and/or trailing edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -2537,7 +2537,7 @@ source.addEventListener('message', _.debounce(batchLog, 250, { ### `_.defer(func, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4936 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be provided to `func` when it is invoked. @@ -2562,7 +2562,7 @@ _.defer(function(text) { console.log(text); }, 'deferred'); ### `_.delay(func, wait, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4953 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4960 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be provided to `func` when it is invoked. @@ -2588,7 +2588,7 @@ _.delay(function(text) { console.log(text); }, 1000, 'later'); ### `_.memoize(func, [resolver])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4998 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5005 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is provided it will be used to determine the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is used as the cache key. The `func` is executed with the `this` binding of the memoized function. The result cache is exposed as the `cache` property on the memoized function. @@ -2631,7 +2631,7 @@ get('pebbles'); ### `_.once(func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5031 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5038 "View in source") [Ⓣ][1] Creates a function that is restricted to execute `func` once. Repeat calls to the function will return the value of the first call. The `func` is executed with the `this` binding of the created function. @@ -2657,7 +2657,7 @@ initialize(); ### `_.partial(func, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5072 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5079 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those provided to the new function. This method is similar to `_.bind` except it does **not** alter the `this` binding. @@ -2686,7 +2686,7 @@ hi('fred'); ### `_.partialRight(func, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5110 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5117 "View in source") [Ⓣ][1] This method is like `_.partial` except that `partial` arguments are appended to those provided to the new function. @@ -2725,7 +2725,7 @@ options.imports ### `_.throttle(func, wait, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5149 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5156 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. Provide an options object to indicate that `func` should be invoked on the leading and/or trailing edge of the `wait` timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2761,7 +2761,7 @@ jQuery('.interactive').on('click', _.throttle(renewToken, 300000, { ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5190 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5197 "View in source") [Ⓣ][1] Creates a function that provides `value` to the wrapper function as its first argument. Additional arguments provided to the function are appended to those provided to the wrapper function. The wrapper is executed with the `this` binding of the created function. @@ -2797,7 +2797,7 @@ p('fred, barney, & pebbles'); ### `_.assign(object, [source], [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5226 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5233 "View in source") [Ⓣ][1] Assigns own enumerable properties of source object(s) to the destination object. Subsequent sources will overwrite property assignments of previous sources. If a callback is provided it will be executed to produce the assigned values. The callback is bound to `thisArg` and invoked with two arguments; *(objectValue, sourceValue)*. @@ -2835,7 +2835,7 @@ defaults(object, { 'name': 'fred', 'employer': 'slate' }); ### `_.clone(value, [isDeep=false], [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5305 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5312 "View in source") [Ⓣ][1] Creates a clone of `value`. If `isDeep` is `true` nested objects will also be cloned, otherwise they will be assigned by reference. If a callback is provided it will be executed to produce the cloned values. If the callback returns `undefined` cloning will be handled by the method instead. The callback is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2884,7 +2884,7 @@ clone.childNodes.length; ### `_.cloneDeep(value, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5365 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5372 "View in source") [Ⓣ][1] Creates a deep clone of `value`. If a callback is provided it will be executed to produce the cloned values. If the callback returns `undefined` cloning will be handled by the method instead. The callback is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2930,7 +2930,7 @@ clone.node == view.node; ### `_.create(prototype, [properties])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5400 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5407 "View in source") [Ⓣ][1] Creates an object that inherits from the given `prototype` object. If a `properties` object is provided its own enumerable properties are assigned to the created object. @@ -2970,7 +2970,7 @@ circle instanceof Shape; ### `_.defaults(object, [source])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5424 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5431 "View in source") [Ⓣ][1] Assigns own enumerable properties of source object(s) to the destination object for all destination properties that resolve to `undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -2996,7 +2996,7 @@ _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); ### `_.findKey(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5494 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5501 "View in source") [Ⓣ][1] This method is like `_.findIndex` except that it returns the key of the first element that passes the callback check, instead of the element itself. @@ -3042,7 +3042,7 @@ _.findKey(characters, 'blocked'); ### `_.findLastKey(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5548 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5555 "View in source") [Ⓣ][1] This method is like `_.findKey` except that it iterates over elements of a `collection` in the opposite order. @@ -3088,7 +3088,7 @@ _.findLastKey(characters, 'blocked'); ### `_.forIn(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5592 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5599 "View in source") [Ⓣ][1] Iterates over own and inherited enumerable properties of an object, executing the callback for each property. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -3126,7 +3126,7 @@ _.forIn(new Shape, function(value, key) { ### `_.forInRight(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5625 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5632 "View in source") [Ⓣ][1] This method is like `_.forIn` except that it iterates over elements of a `collection` in the opposite order. @@ -3164,7 +3164,7 @@ _.forInRight(new Shape, function(value, key) { ### `_.forOwn(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5661 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5668 "View in source") [Ⓣ][1] Iterates over own enumerable properties of an object, executing the callback for each property. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -3192,7 +3192,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.forOwnRight(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5684 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5691 "View in source") [Ⓣ][1] This method is like `_.forOwn` except that it iterates over elements of a `collection` in the opposite order. @@ -3220,7 +3220,7 @@ _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5713 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5720 "View in source") [Ⓣ][1] Creates a sorted array of property names of all enumerable properties, own and inherited, of `object` that have function values. @@ -3247,7 +3247,7 @@ _.functions(_); ### `_.has(object, key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5738 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5745 "View in source") [Ⓣ][1] Checks if the specified property name exists as a direct property of `object`, instead of an inherited property. @@ -3272,7 +3272,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.invert(object, [multiValue=false])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5767 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5774 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given object. If the given object contains duplicate values, subsequent values will overwrite property assignments of previous values unless `multiValue` is `true`. @@ -3332,7 +3332,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5808 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5815 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -3359,7 +3359,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5826 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5833 "View in source") [Ⓣ][1] Checks if `value` is a boolean value. @@ -3383,7 +3383,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5844 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5851 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -3407,7 +3407,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5861 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5868 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -3431,7 +3431,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5894 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5901 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -3461,7 +3461,7 @@ _.isEmpty(''); ### `_.isEqual(a, b, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5951 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5958 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. If a callback is provided it will be executed to compare values. If the callback returns `undefined` comparisons will be handled by the method instead. The callback is bound to `thisArg` and invoked with two arguments; *(a, b)*. @@ -3506,7 +3506,7 @@ _.isEqual(words, otherWords, function(a, b) { ### `_.isFinite(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5984 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5991 "View in source") [Ⓣ][1] Checks if `value` is, or can be coerced to, a finite number. @@ -3544,7 +3544,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6001 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6008 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -3568,7 +3568,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6066 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6073 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. @@ -3603,7 +3603,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6088 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6095 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -3630,7 +3630,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6108 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6115 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -3656,7 +3656,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6031 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6038 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -3686,7 +3686,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6138 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6145 "View in source") [Ⓣ][1] Checks if `value` is an object created by the `Object` constructor. @@ -3721,7 +3721,7 @@ _.isPlainObject({ 'x': 0, 'y': 0 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6170 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -3745,7 +3745,7 @@ _.isRegExp(/fred/); ### `_.isString(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6182 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6189 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -3769,7 +3769,7 @@ _.isString('fred'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6200 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6207 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -3793,7 +3793,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6217 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6224 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of an object. @@ -3817,7 +3817,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.mapValues(object, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6264 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6271 "View in source") [Ⓣ][1] Creates an object with the same keys as `object` and values generated by running each own enumerable property of `object` through the callback. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -3856,7 +3856,7 @@ _.mapValues(characters, 'age'); ### `_.merge(object, [source], [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6325 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6332 "View in source") [Ⓣ][1] Recursively merges own enumerable properties of the source object(s), that don't resolve to `undefined` into the destination object. Subsequent sources will overwrite property assignments of previous sources. If a callback is provided it will be executed to produce the merged values of the destination and source properties. If the callback returns `undefined` merging will be handled by the method instead. The callback is bound to `thisArg` and invoked with two arguments; *(objectValue, sourceValue)*. @@ -3912,7 +3912,7 @@ _.merge(food, otherFood, function(a, b) { ### `_.omit(object, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6383 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6390 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If a callback is provided it will be executed for each property of `object` omitting the properties the callback returns truey for. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -3943,7 +3943,7 @@ _.omit({ 'name': 'fred', 'age': 40 }, function(value) { ### `_.pairs(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6424 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6431 "View in source") [Ⓣ][1] Creates a two dimensional array of an object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -3967,7 +3967,7 @@ _.pairs({ 'barney': 36, 'fred': 40 }); ### `_.pick(object, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6464 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6471 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If a callback is provided it will be executed for each property of `object` picking the properties the callback returns truey for. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -3998,7 +3998,7 @@ _.pick({ 'name': 'fred', '_userid': 'fred1' }, function(value, key) { ### `_.transform(object, [callback=identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6519 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6526 "View in source") [Ⓣ][1] An alternative to `_.reduce`; this method transforms `object` to a new `accumulator` object which is the result of running each of its own enumerable properties through a callback, with each callback execution potentially mutating the `accumulator` object. The callback is bound to `thisArg` and invoked with four arguments; *(accumulator, value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -4035,7 +4035,7 @@ var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) ### `_.values(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6553 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6560 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -4066,7 +4066,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.capitalize(string)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6580 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6587 "View in source") [Ⓣ][1] Converts the first character of `string` to upper case. @@ -4090,7 +4090,7 @@ _.capitalize('fred'); ### `_.escape(string)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6609 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6616 "View in source") [Ⓣ][1] Converts the characters "&", "<", ">", '"', and "'" in `string` to their corresponding HTML entities. @@ -4118,7 +4118,7 @@ _.escape('fred, barney, & pebbles'); ### `_.template(text, [data], [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6700 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6707 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -4210,7 +4210,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.trim(string, [chars=whitespace])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6817 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6824 "View in source") [Ⓣ][1] Removes leading and trailing whitespace or specified characters from `string`. @@ -4238,7 +4238,7 @@ _.trim('-_-fred-_-', '_-'); ### `_.trimLeft(string, [chars=whitespace])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6841 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6848 "View in source") [Ⓣ][1] Removes leading whitespace or specified characters from `string`. @@ -4266,7 +4266,7 @@ _.trimLeft('-_-fred-_-', '_-'); ### `_.trimRight(string, [chars=whitespace])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6865 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6872 "View in source") [Ⓣ][1] Removes trailing whitespace or specified characters from `string`. @@ -4294,7 +4294,7 @@ _.trimRight('-_-fred-_-', '_-'); ### `_.unescape(string)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6890 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6897 "View in source") [Ⓣ][1] The inverse of `_.escape`; this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -4327,7 +4327,7 @@ _.unescape('fred, barney & pebbles'); ### `_.now` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7162 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7169 "View in source") [Ⓣ][1] *(unknown)*: Gets the number of milliseconds that have elapsed since the Unix epoch *(1 January `1970 00`:00:00 UTC)*. @@ -4346,7 +4346,7 @@ _.defer(function() { console.log(_.now() - stamp); }); ### `_.constant(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6915 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6922 "View in source") [Ⓣ][1] Creates a function that returns `value`. @@ -4372,7 +4372,7 @@ getter() === object; ### `_.createCallback([func=identity], [thisArg], [argCount])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6953 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6960 "View in source") [Ⓣ][1] Produces a callback bound to an optional `thisArg`. If `func` is a property name the created callback will return the property value for a given element. If `func` is an object the created callback will return `true` for elements that contain the equivalent object properties, otherwise it will return `false`. @@ -4414,7 +4414,7 @@ _.filter(characters, 'age__gt38'); ### `_.identity(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6976 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6983 "View in source") [Ⓣ][1] This method returns the first argument provided to it. @@ -4439,7 +4439,7 @@ _.identity(object) === object; ### `_.match(props)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7005 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7012 "View in source") [Ⓣ][1] Creates a "_.where" style function, which performs a deep comparison between a given object and the `props` object, returning `true` if the given object has equivalent property values, else `false`. @@ -4473,7 +4473,7 @@ _.find(characters, matchAge); ### `_.mixin([object=lodash], source, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7068 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7075 "View in source") [Ⓣ][1] Adds function properties of a source object to the destination object. If `object` is a function methods will be added to its prototype as well. @@ -4511,7 +4511,7 @@ _('fred').vowels(); ### `_.noConflict()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7128 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7135 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -4531,7 +4531,7 @@ var lodash = _.noConflict(); ### `_.noop()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7145 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7152 "View in source") [Ⓣ][1] A no-operation function. @@ -4550,7 +4550,7 @@ _.noop(object) === undefined; ### `_.parseInt(value, [radix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7186 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7193 "View in source") [Ⓣ][1] Converts `value` to an integer of the specified radix. If `radix` is `undefined` or `0` a `radix` of `10` is used unless the `value` is a hexadecimal, in which case a `radix` of `16` is used. @@ -4577,7 +4577,7 @@ _.parseInt('08'); ### `_.property(key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7217 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7224 "View in source") [Ⓣ][1] Creates a "_.pluck" style function, which returns the `key` value of a given object. @@ -4611,7 +4611,7 @@ _.sortBy(characters, getName); ### `_.random([min=0], [max=1], [floating=false])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7250 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7257 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is provided a number between `0` and the given number will be returned. If `floating` is truey or either `min` or `max` are floats a floating-point number will be returned instead of an integer. @@ -4646,7 +4646,7 @@ _.random(1.2, 5.2); ### `_.result(object, key, [defaultValue])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7315 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7322 "View in source") [Ⓣ][1] Resolves the value of property `key` on `object`. If `key` is a function it will be invoked with the `this` binding of `object` and its result returned, else the property value is returned. If `object` is `null` or `undefined` then `undefined` is returned. If a default value is provided it will be returned if the property value resolves to `undefined`. @@ -4703,7 +4703,7 @@ Create a new `lodash` function using the given context object. ### `_.times(n, callback, [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7346 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7353 "View in source") [Ⓣ][1] Executes the callback `n` times, returning an array of the results of each callback execution. The callback is bound to `thisArg` and invoked with one argument; *(index)*. @@ -4735,7 +4735,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7374 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7381 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is provided the ID will be appended to it. @@ -4788,7 +4788,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7582 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7589 "View in source") [Ⓣ][1] *(string)*: The semantic version number. diff --git a/lodash.js b/lodash.js index 3bd2241a4..6c0ab5b0b 100644 --- a/lodash.js +++ b/lodash.js @@ -3875,15 +3875,22 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var args = slice(arguments, 2), - index = -1, + var index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); - }); + if (arguments.length < 3 && isArray(collection)) { + while (++index < length) { + var value = collection[index]; + result[index] = isFunc ? methodName.call(value) : value[methodName](); + } + } else { + var args = slice(arguments, 2); + baseEach(collection, function(value) { + result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + }); + } return result; } diff --git a/perf/perf.js b/perf/perf.js index 535d5c471..0e4af6f05 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -1228,30 +1228,40 @@ suites.push( Benchmark.Suite('`_.invoke` iterating an array') .add(buildName, '\ - lodash.invoke(numbers, "toFixed", "2")' + lodash.invoke(numbers, "toFixed")' ) .add(otherName, '\ - _.invoke(numbers, "toFixed", "2")' + _.invoke(numbers, "toFixed")' + ) + ); + + suites.push( + Benchmark.Suite('`_.invoke` with arguments iterating an array') + .add(buildName, '\ + lodash.invoke(numbers, "toFixed", 1)' + ) + .add(otherName, '\ + _.invoke(numbers, "toFixed", 1)' ) ); suites.push( Benchmark.Suite('`_.invoke` with a function for `methodName` iterating an array') .add(buildName, '\ - lodash.invoke(numbers, String.prototype.split, "")' + lodash.invoke(numbers, Number.prototype.toFixed, 1)' ) .add(otherName, '\ - _.invoke(numbers, String.prototype.split, "")' + _.invoke(numbers, Number.prototype.toFixed, 1)' ) ); suites.push( Benchmark.Suite('`_.invoke` iterating an object') .add(buildName, '\ - lodash.invoke(object, "toFixed", "2")' + lodash.invoke(object, "toFixed", 1)' ) .add(otherName, '\ - _.invoke(object, "toFixed", "2")' + _.invoke(object, "toFixed", 1)' ) );