diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index af7e211d2..f479d3020 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -1322,7 +1322,7 @@ } } // exit early if there are no `this` references or `func` is bound - if (bindData === false || (bindData !== true && bindData[1] & 1)) { + if (bindData === false || (bindData !== true && bindData[1] & BIND_FLAG)) { return func; } switch (argCount) { @@ -7226,36 +7226,43 @@ /** * 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 falsey then `undefined` - * is returned. + * 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`. * * @static * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. * @param {string} key The name of the property to resolve. + * @param {*} [defaultValue] The value returned if the property value + * resolves to `undefined`. * @returns {*} Returns the resolved value. * @example * * var object = { - * 'cheese': 'crumpets', - * 'stuff': function() { - * return 'nonsense'; + * 'name': 'fred', + * 'age': function() { + * return 40; * } * }; * - * _.result(object, 'cheese'); - * // => 'crumpets' + * _.result(object, 'name'); + * // => 'fred' * - * _.result(object, 'stuff'); - * // => 'nonsense' + * _.result(object, 'age'); + * // => 40 + * + * _.result(object, 'employer', 'slate'); + * // => 'slate' */ - function result(object, key) { - if (object) { - var value = object[key]; - return isFunction(value) ? object[key]() : value; + function result(object, key, defaultValue) { + if (object == null) { + return defaultValue; } + var value = typeof object[key] != 'undefined' ? object[key] : defaultValue; + return isFunction(value) ? object[key]() : value; } /** diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 3a542922e..5774f5506 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,60 +5,60 @@ */ ;(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=T&&o===t,l=[];if(i){var c=f(e);c?(o=r,e=c):i=false}for(;++uo(e,c)&&l.push(c);return i&&y(e),l}function gt(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:k(t,r,3),typeof o=="number")for(ue.unindexedChars&&ar(u)&&(u=u.split(""));++e=T&&o===t,l=[];if(i){var c=f(e);c?(o=r,e=c):i=false}for(;++uo(e,c)&&l.push(c);return i&&y(e),l}function gt(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:k(t,r,3),typeof o=="number")for(ue.unindexedChars&&ar(u)&&(u=u.split(""));++e=T&&a===t,s=u||c?p():l;for(c&&(s=f(s),a=r);++oa(s,h))&&((u||c)&&s.push(h),l.push(g)) -}return c?(v(s.g),y(s)):u&&v(s),l}function wt(n){return function(t,r,u){var o={};if(r=e.createCallback(r,u,3),pe(t)){u=-1;for(var a=t.length;++u=T&&a===t,p=u||c?s():l;for(c&&(p=f(p),a=r);++oa(p,h))&&((u||c)&&p.push(h),l.push(g)) +}return c?(v(p.g),y(p)):u&&v(p),l}function wt(n){return function(t,r,u){var o={};if(r=e.createCallback(r,u,3),se(t)){u=-1;for(var a=t.length;++uu;u++)e+="m='"+n.d[u]+"';if((!(l&&o[m])&&h.call(q,m))",n.f||(e+="||(!o[m]&&q[m]!==r[m])"),e+="){"+n.c+"}"; -e+="}"}return t("a,f,g,h,j,k,r,p,v,w,y",r+(e+"return s;")+"}")(k,ut,Cr,Dr,Et,ur,kr,ee,ft,Or,Sr)}function Ct(){var n=(n=e.indexOf)===St?t:n;return n}function kt(n){return typeof n=="function"&&Ar.test(Tr.call(n))}function Ot(n){var t,r;return!n||Sr.call(n)!=it||!Dr.call(n,"constructor")&&(t=n.constructor,er(t)&&!(t instanceof t))||!ue.argsClass&&Et(n)||!ue.nodeClass&&h(n)?false:ue.ownLast?(se(n,function(n,t,e){return r=Dr.call(e,t),false}),false!==r):(se(n,function(n,t){r=t}),typeof r=="undefined"||Dr.call(n,r)) +e+="}"}return t("a,f,g,h,j,k,r,p,v,w,y",r+(e+"return s;")+"}")(k,ut,Cr,Dr,Et,ur,kr,ee,ft,Or,Sr)}function Ct(){var n=(n=e.indexOf)===St?t:n;return n}function kt(n){return typeof n=="function"&&Ar.test(Tr.call(n))}function Ot(n){var t,r;return!n||Sr.call(n)!=it||!Dr.call(n,"constructor")&&(t=n.constructor,er(t)&&!(t instanceof t))||!ue.argsClass&&Et(n)||!ue.nodeClass&&h(n)?false:ue.ownLast?(pe(n,function(n,t,e){return r=Dr.call(e,t),false}),false!==r):(pe(n,function(n,t){r=t}),typeof r=="undefined"||Dr.call(n,r)) }function Et(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Sr.call(n)==nt||false}function qt(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=-1;for(t=e.createCallback(t,r,3);++ae?Hr(0,u+e):e||0;else if(e)return e=Nt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function At(n,t,r){if(typeof t!="number"&&null!=t){var u=0,o=-1,a=n?n.length:0; for(t=e.createCallback(t,r,3);++ot?t=Hr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Hr(u+r,0):r>u&&(r=u),u=r-t||0,r=gr(u);++e>>1,r(n[u])r?0:r);++t=e)return false;if(typeof n=="string"||!pe(n)&&ar(n))return Kr?Kr.call(n,t,r):-1r?Hr(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&ar(n)?u:e.createCallback(t,r,3),gt(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Ut(n,t,r,u){var o=3>arguments.length; -if(t=e.createCallback(t,u,4),pe(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),zt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Xt(n){var t=-1,r=n?n.length:0,e=gr(typeof r=="number"?r:0);return Wt(n,function(n){var r=dt(0,++t);e[t]=e[r],e[r]=n}),e}function Gt(n,t,r){var u;if(t=e.createCallback(t,r,3),pe(n)){r=-1;for(var o=n.length;++r=y;m?(a&&(a=Nr(a)),p=l,i=n.apply(f,o)):a||(a=Lr(e,y))}return m&&c?c=Nr(c):c||t===g||(c=Lr(u,t)),r&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Qt(n,t,r){var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3r?0:r);++t=e)return false;if(typeof n=="string"||!se(n)&&ar(n))return Kr?Kr.call(n,t,r):-1r?Hr(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&ar(n)?u:e.createCallback(t,r,3),gt(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Ut(n,t,r,u){var o=3>arguments.length; +if(t=e.createCallback(t,u,4),se(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),zt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Xt(n){var t=-1,r=n?n.length:0,e=gr(typeof r=="number"?r:0);return Wt(n,function(n){var r=dt(0,++t);e[t]=e[r],e[r]=n}),e}function Gt(n,t,r){var u;if(t=e.createCallback(t,r,3),se(n)){r=-1;for(var o=n.length;++r=y;m?(a&&(a=Nr(a)),s=l,i=n.apply(f,o)):a||(a=Lr(e,y))}return m&&c?c=Nr(c):c||t===g||(c=Lr(u,t)),r&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Qt(n,t,r){var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3--n?t.apply(this,arguments):void 0}},e.assign=Qt,e.at=function(n,t){var r=arguments,e=-1,u=ht(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),ue.unindexedChars&&ar(n)&&(n=n.split("")),r=gr(o);++e=T&&f(e?n[e]:l)))}var i=n[0],s=-1,g=i?i.length:0,h=[];n:for(;++s(m?r(m,c):a(l,c))){for(e=u,(m||l).push(c);--e;)if(m=o[e],0>(m?r(m,c):a(n[e],c)))continue n;h.push(c) +}},e.countBy=ie,e.create=function(n,t){var r=w(n);return t?Qt(r,t):r},e.createCallback=function(n,t,r){var e=typeof n;return null==n||"function"==e?k(n,t,r):"object"!=e?sr(n):fr(n)},e.curry=function(n,t){return t=typeof t=="number"?t:+t||n.length,jt(n,A,null,null,null,t)},e.debounce=Jt,e.defaults=Yt,e.defer=function(n){if(!er(n))throw new jr;var t=It(arguments,1);return Lr(function(){n.apply(C,t)},1)},e.delay=function(n,t){if(!er(n))throw new jr;var r=It(arguments,2);return Lr(function(){n.apply(C,r) +},t)},e.difference=function(n){return P(n,ht(arguments,true,true,1))},e.filter=Lt,e.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=Kt(n,r,e)),ht(n,t)},e.forEach=Wt,e.forEachRight=zt,e.forIn=pe,e.forInRight=function(n,t,r){var e=[];pe(n,function(n,t){e.push(t,n)});var u=e.length;for(t=k(t,r,3);u--&&false!==t(e[u--],e[u],n););return n},e.forOwn=Zt,e.forOwnRight=nr,e.functions=tr,e.groupBy=le,e.indexBy=fe,e.initial=function(n,t,r){var u=0,o=n?n.length:0; +if(typeof t!="number"&&null!=t){var a=o;for(t=e.createCallback(t,r,3);a--&&t(n[a],a,n);)u++}else u=null==t||r?1:t||u;return u=o-u,It(n,0,0=T&&f(e?n[e]:l)))}var i=n[0],p=-1,g=i?i.length:0,h=[];n:for(;++p(m?r(m,c):a(l,c))){for(e=u,(m||l).push(c);--e;)if(m=o[e],0>(m?r(m,c):a(n[e],c)))continue n;h.push(c) }}for(;u--;)(m=o[u])&&y(m);return v(o),v(l),h},e.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},e.mixin=cr,e.noConflict=function(){return n._=qr,this},e.noop=sr,e.now=de,e.parseInt=be,e.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=Yr(),Jr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):dt(n,t) -},e.reduce=Ut,e.reduceRight=Vt,e.result=function(n,t){if(n){var r=n[t];return er(r)?n[t]():r}},e.runInContext=x,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:he(n).length},e.some=Gt,e.sortedIndex=Nt,e.template=function(n,t,r){var u=e.templateSettings;n=wr(n||""),r=Yt({},r,u);var o,a=Yt({},r.imports,u.imports),u=he(a),a=ir(a),i=0,l=r.interpolate||H,f="__p+='",l=_r((r.escape||H).source+"|"+l.source+"|"+(l===M?U:H).source+"|"+(r.evaluate||H).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),f+=n.slice(i,l).replace(Q,s),r&&(f+="'+__e("+r+")+'"),a&&(o=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t -}),f+="';",l=r=r.variable,l||(r="obj",f="with("+r+"){"+f+"}"),f=(o?f.replace(F,""):f).replace($,"$1").replace(L,"$1;"),f="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=yr(u,"return "+f).apply(C,a)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},e.trim=ve,e.trimLeft=ye,e.trimRight=me,e.unescape=function(n){return null==n?"":(n=wr(n),0>n.indexOf(";")?n:n.replace(B,j)) -},e.uniqueId=function(n){var t=++E;return wr(null==n?"":n)+t},e.all=$t,e.any=Gt,e.detect=Bt,e.findWhere=Bt,e.foldl=Ut,e.foldr=Vt,e.include=Ft,e.inject=Ut,cr(function(){var n={};return Zt(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=qt,e.last=function(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o;for(t=e.createCallback(t,r,3);a--&&t(n[a],a,n);)u++}else if(u=t,null==u||r)return n?n[o-1]:C;return u=o-u,It(n,0"']/g,z=/<%-([\s\S]+?)%>/g,K=/<%([\s\S]+?)%>/g,M=/<%=([\s\S]+?)%>/g,U=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,V=/\w*$/,X=/^\s*function[ \n\r\t]+\w/,G=/^0[xX]/,H=/($^)/,J=/\bthis\b/,Q=/['\n\r\t\u2028\u2029\\]/g,Y="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Z="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),nt="[object Arguments]",tt="[object Array]",rt="[object Boolean]",et="[object Date]",ut="[object Error]",ot="[object Function]",at="[object Number]",it="[object Object]",lt="[object RegExp]",ft="[object String]",ct={}; -ct[ot]=false,ct[nt]=ct[tt]=ct[rt]=ct[et]=ct[at]=ct[it]=ct[lt]=ct[ft]=true;var st={leading:false,maxWait:0,trailing:false},pt={configurable:false,enumerable:false,value:null,writable:false},gt={"&":"&","<":"<",">":">",'"':""","'":"'"},ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},vt={"function":true,object:true},yt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},mt=vt[typeof window]&&window||this,dt=vt[typeof exports]&&exports&&!exports.nodeType&&exports,bt=vt[typeof global]&&global; +},e.isString=ar,e.isUndefined=function(n){return typeof n=="undefined"},e.lastIndexOf=function(n,t,r){var e=n?n.length:0;for(typeof r=="number"&&(e=(0>r?Hr(0,e+r):Jr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=cr,e.noConflict=function(){return n._=qr,this},e.noop=pr,e.now=de,e.parseInt=be,e.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=Yr(),Jr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):dt(n,t) +},e.reduce=Ut,e.reduceRight=Vt,e.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,er(r)?n[t]():r)},e.runInContext=x,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:he(n).length},e.some=Gt,e.sortedIndex=Nt,e.template=function(n,t,r){var u=e.templateSettings;n=wr(n||""),r=Yt({},r,u);var o,a=Yt({},r.imports,u.imports),u=he(a),a=ir(a),i=0,l=r.interpolate||H,f="__p+='",l=_r((r.escape||H).source+"|"+l.source+"|"+(l===M?U:H).source+"|"+(r.evaluate||H).source+"|$","g"); +n.replace(l,function(t,r,e,u,a,l){return e||(e=u),f+=n.slice(i,l).replace(Q,p),r&&(f+="'+__e("+r+")+'"),a&&(o=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t}),f+="';",l=r=r.variable,l||(r="obj",f="with("+r+"){"+f+"}"),f=(o?f.replace(F,""):f).replace($,"$1").replace(L,"$1;"),f="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=yr(u,"return "+f).apply(C,a) +}catch(s){throw s.source=f,s}return t?c(t):(c.source=f,c)},e.trim=ve,e.trimLeft=ye,e.trimRight=me,e.unescape=function(n){return null==n?"":(n=wr(n),0>n.indexOf(";")?n:n.replace(B,j))},e.uniqueId=function(n){var t=++E;return wr(null==n?"":n)+t},e.all=$t,e.any=Gt,e.detect=Bt,e.findWhere=Bt,e.foldl=Ut,e.foldr=Vt,e.include=Ft,e.inject=Ut,cr(function(){var n={};return Zt(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=qt,e.last=function(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o; +for(t=e.createCallback(t,r,3);a--&&t(n[a],a,n);)u++}else if(u=t,null==u||r)return n?n[o-1]:C;return u=o-u,It(n,0"']/g,z=/<%-([\s\S]+?)%>/g,K=/<%([\s\S]+?)%>/g,M=/<%=([\s\S]+?)%>/g,U=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,V=/\w*$/,X=/^\s*function[ \n\r\t]+\w/,G=/^0[xX]/,H=/($^)/,J=/\bthis\b/,Q=/['\n\r\t\u2028\u2029\\]/g,Y="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Z="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),nt="[object Arguments]",tt="[object Array]",rt="[object Boolean]",et="[object Date]",ut="[object Error]",ot="[object Function]",at="[object Number]",it="[object Object]",lt="[object RegExp]",ft="[object String]",ct={}; +ct[ot]=false,ct[nt]=ct[tt]=ct[rt]=ct[et]=ct[at]=ct[it]=ct[lt]=ct[ft]=true;var pt={leading:false,maxWait:0,trailing:false},st={configurable:false,enumerable:false,value:null,writable:false},gt={"&":"&","<":"<",">":">",'"':""","'":"'"},ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},vt={"function":true,object:true},yt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},mt=vt[typeof window]&&window||this,dt=vt[typeof exports]&&exports&&!exports.nodeType&&exports,bt=vt[typeof global]&&global; !bt||bt.global!==bt&&bt.window!==bt||(mt=bt);var bt=(vt=vt[typeof module]&&module&&!module.nodeType&&module)&&vt.exports===dt&&dt,_t=x();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(mt._=_t, define(function(){return _t})):dt&&vt?bt?(vt.exports=_t)._=_t:dt._=_t:mt._=_t}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 48429274a..0f206a255 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -1098,7 +1098,7 @@ } } // exit early if there are no `this` references or `func` is bound - if (bindData === false || (bindData !== true && bindData[1] & 1)) { + if (bindData === false || (bindData !== true && bindData[1] & BIND_FLAG)) { return func; } switch (argCount) { @@ -6907,36 +6907,43 @@ /** * 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 falsey then `undefined` - * is returned. + * 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`. * * @static * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. * @param {string} key The name of the property to resolve. + * @param {*} [defaultValue] The value returned if the property value + * resolves to `undefined`. * @returns {*} Returns the resolved value. * @example * * var object = { - * 'cheese': 'crumpets', - * 'stuff': function() { - * return 'nonsense'; + * 'name': 'fred', + * 'age': function() { + * return 40; * } * }; * - * _.result(object, 'cheese'); - * // => 'crumpets' + * _.result(object, 'name'); + * // => 'fred' * - * _.result(object, 'stuff'); - * // => 'nonsense' + * _.result(object, 'age'); + * // => 40 + * + * _.result(object, 'employer', 'slate'); + * // => 'slate' */ - function result(object, key) { - if (object) { - var value = object[key]; - return isFunction(value) ? object[key]() : value; + function result(object, key, defaultValue) { + if (object == null) { + return defaultValue; } + var value = typeof object[key] != 'undefined' ? object[key] : defaultValue; + return isFunction(value) ? object[key]() : value; } /** diff --git a/dist/lodash.min.js b/dist/lodash.min.js index a728edcff..db39b06a2 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -10,7 +10,7 @@ t&&v(t),n.g=n.h=n.i=n.object=n.number=n.string=n.k=null,C.lengthr||13r||8202=T&&o===t,f=[];if(a){var c=l(e);c?(o=r,e=c):a=false}for(;++uo(e,c)&&f.push(c);return a&&v(e),f}function st(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++er?Mr(0,e+r):Ur(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},i.mixin=ar,i.noConflict=function(){return n._=xr,this},i.noop=fr,i.now=pe,i.parseInt=se,i.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=Xr(),Ur(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):yt(n,t)},i.reduce=Pt,i.reduceRight=Kt,i.result=function(n,t){if(n){var r=n[t]; -return nr(r)?n[t]():r}},i.runInContext=j,i.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ae(n).length},i.some=Ut,i.sortedIndex=Nt,i.template=function(n,t,r){var e=i.templateSettings;n=br(n||""),r=Ht({},r,e);var u,o=Ht({},r.imports,e.imports),e=ae(o),o=ur(o),a=0,f=r.interpolate||G,l="__p+='",f=mr((r.escape||G).source+"|"+f.source+"|"+(f===K?M:G).source+"|"+(r.evaluate||G).source+"|$","g");n.replace(f,function(t,r,e,o,i,f){return e||(e=o),l+=n.slice(a,f).replace(J,p),r&&(l+="'+__e("+r+")+'"),i&&(u=true,l+="';"+i+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t +},i.lastIndexOf=function(n,t,r){var e=n?n.length:0;for(typeof r=="number"&&(e=(0>r?Mr(0,e+r):Ur(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},i.mixin=ar,i.noConflict=function(){return n._=xr,this},i.noop=fr,i.now=pe,i.parseInt=se,i.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=Xr(),Ur(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):yt(n,t)},i.reduce=Pt,i.reduceRight=Kt,i.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,nr(r)?n[t]():r) +},i.runInContext=j,i.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ae(n).length},i.some=Ut,i.sortedIndex=Nt,i.template=function(n,t,r){var e=i.templateSettings;n=br(n||""),r=Ht({},r,e);var u,o=Ht({},r.imports,e.imports),e=ae(o),o=ur(o),a=0,f=r.interpolate||G,l="__p+='",f=mr((r.escape||G).source+"|"+f.source+"|"+(f===K?M:G).source+"|"+(r.evaluate||G).source+"|$","g");n.replace(f,function(t,r,e,o,i,f){return e||(e=o),l+=n.slice(a,f).replace(J,p),r&&(l+="'+__e("+r+")+'"),i&&(u=true,l+="';"+i+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t }),l+="';",f=r=r.variable,f||(r="obj",l="with("+r+"){"+l+"}"),l=(u?l.replace($,""):l).replace(B,"$1").replace(q,"$1;"),l="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var c=gr(e,"return "+l).apply(k,o)}catch(s){throw s.source=l,s}return t?c(t):(c.source=l,c)},i.trim=fe,i.trimLeft=le,i.trimRight=ce,i.unescape=function(n){return null==n?"":(n=br(n),0>n.indexOf(";")?n:n.replace(W,w)) },i.uniqueId=function(n){var t=++O;return br(null==n?"":n)+t},i.all=Ft,i.any=Ut,i.detect=Bt,i.findWhere=Bt,i.foldl=Pt,i.foldr=Kt,i.include=Dt,i.inject=Pt,ar(function(){var n={};return Jt(i,function(t,r){i.prototype[r]||(n[r]=t)}),n}(),false),i.first=Ct,i.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=i.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:k;return e=u-e,Et(n,0 'crumpets' + * _.result(object, 'name'); + * // => 'fred' * - * _.result(object, 'stuff'); - * // => 'nonsense' + * _.result(object, 'age'); + * // => 40 + * + * _.result(object, 'employer', 'slate'); + * // => 'slate' */ - function result(object, key) { - if (object) { - var value = object[key]; - return isFunction(value) ? object[key]() : value; + function result(object, key, defaultValue) { + if (object == null) { + return defaultValue; } + var value = typeof object[key] != 'undefined' ? object[key] : defaultValue; + return isFunction(value) ? object[key]() : value; } /** diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 936f36880..d114d0ef3 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -33,8 +33,8 @@ o in n&&(u[o]=n[o])}return u},o.pluck=et,o.range=function(n,r,t){n=+n||0,t=+t||1 },o.throttle=function(n,r,t){var e=true,u=true;if(!H(n))throw new TypeError;return false===t?e=false:J(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),t={},t.leading=e,t.maxWait=r,t.trailing=u,z(n,r,t)},o.times=function(n,r,t){n=-1<(n=+n)?n:0;var e=-1,u=Array(n);for(r=c(r,t,1);++er?0:r);++nt?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=nr,o.noConflict=function(){return Or._=Rr,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+Dr(Xr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r){if(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:it(n).length},o.some=M,o.sortedIndex=T,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(n||"")+"",t=P({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||gr).source+"|"+(t.interpolate||gr).source+"|"+(t.evaluate||gr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(vr,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 c=Function("_","return "+a)(u)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(pr,u))},o.uniqueId=function(n){var r=++er+"";return n?n+r:r},o.all=O,o.any=M,o.detect=S,o.findWhere=function(n,r){return D(n,r,true)},o.foldl=R,o.foldr=$,o.include=E,o.inject=R,o.first=d,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,x(n,0t?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=nr,o.noConflict=function(){return Or._=Rr,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+Dr(Xr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r,t){return null==n?t:(t="undefined"!=typeof n[r]?n[r]:t,H(t)?n[r]():t) +},o.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:it(n).length},o.some=M,o.sortedIndex=T,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(n||"")+"",t=P({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||gr).source+"|"+(t.interpolate||gr).source+"|"+(t.evaluate||gr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(vr,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 c=Function("_","return "+a)(u)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(pr,u))},o.uniqueId=function(n){var r=++er+"";return n?n+r:r},o.all=O,o.any=M,o.detect=S,o.findWhere=function(n,r){return D(n,r,true)},o.foldl=R,o.foldr=$,o.include=E,o.inject=R,o.first=d,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,x(n,0