Simplify null/undefined check in _.isEqual and edit _.cloneDeep docs.

Former-commit-id: 62455ba83df04318856fbc889743f44101b24fe3
This commit is contained in:
John-David Dalton
2013-01-25 00:20:55 -08:00
parent 0fc2ab4d41
commit 98eccf223a
5 changed files with 12 additions and 12 deletions

View File

@@ -1984,7 +1984,7 @@ deep[0] === stooges[0];
Creates a deep clone of `value`. Functions and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and objects created by constructors other than `Object` are cloned to plain `Object` objects.
Note: This function is loosely based on the structured clone algorithm. See http://www.w3.org/TR/html5/common-dom-interfaces.html#internal-structured-cloning-algorithm.
Note: This function is loosely based on the structured clone algorithm. See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
#### Arguments
1. `value` *(Mixed)*: The value to deep clone.

View File

@@ -653,7 +653,7 @@
*
* @private
* @param {Object} [options1, options2, ...] The compile options object(s).
* arrays - A boolean to specify support for iterating arrays and array-like objects.
* arrays - A string of code to determine if the iteratee is an array or array-like.
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
* args - A string of comma separated arguments the iteration function will accept.
* top - A string of code to execute before the iteration branches.
@@ -672,7 +672,7 @@
'shadowed': shadowed,
// iterator options
'arrays': "isArray(iteratee)",
'arrays': 'isArray(iteratee)',
'bottom': '',
'loop': '',
'top': '',
@@ -1129,7 +1129,7 @@
* constructors other than `Object` are cloned to plain `Object` objects.
*
* Note: This function is loosely based on the structured clone algorithm.
* See http://www.w3.org/TR/html5/common-dom-interfaces.html#internal-structured-cloning-algorithm.
* See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
*
* @static
* @memberOf _
@@ -1366,9 +1366,9 @@
// treat `+0` vs. `-0` as not equal
return a !== 0 || (1 / a == 1 / b);
}
// a strict comparison is necessary because `null == undefined`
// exit early for unlike `null` or `undefined` values
if (a == null || b == null) {
return a === b;
return false;
}
// compare [[Class]] names
var className = toString.call(a),

2
lodash.min.js vendored
View File

@@ -9,7 +9,7 @@
for(var u=0;7>u;u++)e+="i='"+t.j[u]+"';if(","constructor"==t.j[u]&&(e+="!(f&&f.prototype===m)&&"),e+="h.call(m,i)){"+t.g+"}"}return(t.b||t.h)&&(e+="}"),e+=t.c+";return u",r("e,h,j,k,l,q,o,t","return function("+n+"){"+e+"}")(a,wt,h,fr,A,nr,Nt,xt)}function c(n){return"\\"+tr[n]}function l(n){return lr[n]}function p(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function s(){}function v(n,t,r){t||(t=0),typeof r=="undefined"&&(r=n?n.length:0);var e=-1;r=r-t||0;for(var u=Array(0>r?0:r);++e<r;)u[e]=n[t+e];
return u}function g(n){return pr[n]}function h(n){return Ot.call(n)==qt}function y(n){var t=!1;if(!n||typeof n!="object"||h(n))return t;var r=n.constructor;return!j(r)&&(!Wt||!p(n))||r instanceof r?Y?(ir(n,function(n,r,e){return t=!wt.call(e,r),!1}),!1===t):(ir(n,function(n,r){t=r}),!1===t||wt.call(n,t)):t}function m(n){var t=[];return ar(n,function(n,r){t.push(r)}),t}function _(n,t,r,e,u){if(null==n)return n;if(r&&(t=!1),r=x(n)){var o=Ot.call(n);if(!Yt[o]||Wt&&p(n))return n;var i=fr(n)}if(!r||!t)return r?i?v(n):sr({},n):n;
switch(r=Zt[o],o){case It:case Tt:return new r(+n);case Bt:case zt:return new r(n);case Pt:return r(n.source,ct.exec(n))}for(e||(e=[]),u||(u=[]),o=e.length;o--;)if(e[o]==n)return u[o];var a=i?r(n.length):{};return e.push(n),u.push(a),(i?F:ar)(n,function(n,r){a[r]=_(n,t,null,e,u)}),i&&(wt.call(n,"index")&&(a.index=n.index),wt.call(n,"input")&&(a.input=n.input)),a}function d(n){var t=[];return ir(n,function(n,r){j(n)&&t.push(r)}),t.sort()}function b(n){for(var t=-1,r=cr(n),e=r.length,u={};++t<e;){var o=r[t];
u[n[o]]=o}return u}function w(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;var u=Ot.call(n),o=Ot.call(t);if(u==qt&&(u=Mt),o==qt&&(o=Mt),u!=o)return!1;switch(u){case It:case Tt:return+n==+t;case Bt:return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case Pt:case zt:return n==t+""}if(o=u==Dt,!o){if(n.__wrapped__||t.__wrapped__)return w(n.__wrapped__||n,t.__wrapped__||t);if(u!=Mt||Wt&&(p(n)||p(t)))return!1;var u=!Ht&&h(n)?Object:n.constructor,i=!Ht&&h(t)?Object:t.constructor;if(u!=i&&(!j(u)||!(u instanceof u&&j(i)&&i instanceof i)))return!1
u[n[o]]=o}return u}function w(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return!1;var u=Ot.call(n),o=Ot.call(t);if(u==qt&&(u=Mt),o==qt&&(o=Mt),u!=o)return!1;switch(u){case It:case Tt:return+n==+t;case Bt:return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case Pt:case zt:return n==t+""}if(o=u==Dt,!o){if(n.__wrapped__||t.__wrapped__)return w(n.__wrapped__||n,t.__wrapped__||t);if(u!=Mt||Wt&&(p(n)||p(t)))return!1;var u=!Ht&&h(n)?Object:n.constructor,i=!Ht&&h(t)?Object:t.constructor;if(u!=i&&(!j(u)||!(u instanceof u&&j(i)&&i instanceof i)))return!1
}for(r||(r=[]),e||(e=[]),u=r.length;u--;)if(r[u]==n)return e[u]==t;var a=!0,f=0;if(r.push(n),e.push(t),o){if(f=n.length,a=f==t.length)for(;f--&&(a=w(n[f],t[f],r,e)););return a}return ir(n,function(n,u,o){return wt.call(o,u)?(f++,a=wt.call(t,u)&&w(n,t[u],r,e)):void 0}),a&&ir(t,function(n,t,r){return wt.call(r,t)?a=-1<--f:void 0}),a}function j(n){return typeof n=="function"}function x(n){return n?nr[typeof n]:!1}function O(n){return typeof n=="number"||Ot.call(n)==Bt}function A(n){return typeof n=="string"||Ot.call(n)==zt
}function S(n,t,r){var e=arguments,u=0,o=2;if(!n)return n;if(r===rt)var i=e[3],f=e[4],c=e[5];else f=[],c=[],typeof r!="number"&&(o=e.length,i=typeof(i=e[o-2])=="function"?a(i,e[--o]):typeof(i=e[o-1])=="function"&&i);for(;++u<o;){var l=fr(e[u]);(l?F:ar)(e[u],function(t,r){var e,u,o=n[r];if(t&&((u=gr(t))||fr(t))){for(var a=f.length;a--;)if(e=f[a]==t){o=c[a];break}e||(o=u?gr(o)?o:{}:fr(o)?o:[],i&&(o=i(o,t)),f.push(t),c.push(o),o=o&&S(o,t,rt,i,f,c))}else i?o=i(o,t):(l||typeof t!="undefined")&&(o=t);n[r]=o
})}return n}function E(n){for(var t=-1,r=cr(n),e=r.length,u=Array(e);++t<e;)u[t]=n[r[t]];return u}function k(n,t,r){var e=-1,u=n?n.length:0,o=!1;return r=(0>r?Rt(0,u+r):r)||0,typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):or(n,function(n){return++e<r?void 0:!(o=n===t)}),o}function N(n,t,r){var e=!0;if(t=a(t,r),fr(n)){r=-1;for(var u=n.length;++r<u&&(e=!!t(n[r],r,n)););}else or(n,function(n,r,u){return e=!!t(n,r,u)});return e}function R(n,t,r){var e=[];if(t=a(t,r),fr(n)){r=-1;for(var u=n.length;++r<u;){var o=n[r];

View File

@@ -415,7 +415,7 @@
*
* @private
* @param {Object} [options1, options2, ...] The compile options object(s).
* arrays - A boolean to specify support for iterating arrays and array-like objects.
* arrays - A string of code to determine if the iteratee is an array or array-like.
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
* args - A string of comma separated arguments the iteration function will accept.
* top - A string of code to execute before the iteration branches.
@@ -433,7 +433,7 @@
'shadowed': shadowed,
// iterator options
'arrays': "isArray(iteratee)",
'arrays': 'isArray(iteratee)',
'bottom': '',
'loop': '',
'top': '',
@@ -1078,9 +1078,9 @@
// treat `+0` vs. `-0` as not equal
return a !== 0 || (1 / a == 1 / b);
}
// a strict comparison is necessary because `null == undefined`
// exit early for unlike `null` or `undefined` values
if (a == null || b == null) {
return a === b;
return false;
}
// compare [[Class]] names
var className = toString.call(a),

View File

@@ -7,7 +7,7 @@
;(function(n,r){function t(n,r){var t;if(n)for(t in r||(r=P),n)if(r(n[t],t,n)===W)break}function e(n,r,t){if(n){r=r&&typeof t=="undefined"?r:i(r,t);var e=n.length;if(t=-1,typeof e=="number")for(;++t<e&&r(n[t],t,n)!==W;);else for(t in n)if(ir.call(n,t)&&r(n[t],t,n)===W)break}}function u(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof u?(this.__wrapped__=n,void 0):new u(n)}function o(n,r){var t=n.b,e=r.b;if(n=n.a,r=r.a,n!==r){if(n>r||typeof n=="undefined")return 1;if(n<r||typeof r=="undefined")return-1
}return t<e?-1:1}function i(n,r,t){if(!n)return P;var e=typeof n;if("function"!=e){if("object"!=e)return function(r){return r[n]};var u=Fr(n);return function(r){for(var t=u.length,e=H;t--&&(e=_(r[u[t]],n[u[t]])););return e}}return typeof r!="undefined"?t?function(t,e,u,o){return n.call(r,t,e,u,o)}:function(t,e,u){return n.call(r,t,e,u)}:n}function a(n){return"\\"+Nr[n]}function f(n){return Rr[n]}function c(){}function l(n,r,t){r||(r=0),typeof t=="undefined"&&(t=n?n.length:0);var e=-1;t=t-r||0;for(var u=Array(0>t?0:t);++e<t;)u[e]=n[r+e];
return u}function s(n){return Tr[n]}function p(n){var r,t=[],e=function(n,r){t.push(r)};if(n)for(r in e||(e=P),n)if(ir.call(n,r)&&e(n[r],r,n)===W)break;return t}function v(n){if(!n)return n;for(var r=1,t=arguments.length;r<t;r++){var e=arguments[r];if(e)for(var u in e)n[u]=e[u]}return n}function g(n){if(!n)return n;for(var r=1,t=arguments.length;r<t;r++){var e=arguments[r];if(e)for(var u in e)n[u]==G&&(n[u]=e[u])}return n}function h(n){var r=[];return t(n,function(n,t){m(n)&&r.push(t)}),r.sort()}function y(n){for(var r=-1,t=Fr(n),e=t.length,u={};++r<e;){var o=t[r];
u[n[o]]=o}return u}function _(n,r,e,u){if(n===r)return 0!==n||1/n==1/r;if(n==G||r==G)return n===r;var o=fr.call(n),i=fr.call(r);if(o!=i)return H;switch(o){case mr:case dr:return+n==+r;case br:return n!=+n?r!=+r:0==n?1/n==1/r:n==+r;case wr:case Ar:return n==r+""}if(i=o==_r,!i){if(n.__wrapped__||r.__wrapped__)return _(n.__wrapped__||n,r.__wrapped__||r);if(o!=jr)return H;var o=n.constructor,a=r.constructor;if(o!=a&&(!m(o)||!(o instanceof o&&m(a)&&a instanceof a)))return H}for(e||(e=[]),u||(u=[]),o=e.length;o--;)if(e[o]==n)return u[o]==r;
u[n[o]]=o}return u}function _(n,r,e,u){if(n===r)return 0!==n||1/n==1/r;if(n==G||r==G)return H;var o=fr.call(n),i=fr.call(r);if(o!=i)return H;switch(o){case mr:case dr:return+n==+r;case br:return n!=+n?r!=+r:0==n?1/n==1/r:n==+r;case wr:case Ar:return n==r+""}if(i=o==_r,!i){if(n.__wrapped__||r.__wrapped__)return _(n.__wrapped__||n,r.__wrapped__||r);if(o!=jr)return H;var o=n.constructor,a=r.constructor;if(o!=a&&(!m(o)||!(o instanceof o&&m(a)&&a instanceof a)))return H}for(e||(e=[]),u||(u=[]),o=e.length;o--;)if(e[o]==n)return u[o]==r;
var f=V,c=0;if(e.push(n),u.push(r),i){if(c=n.length,f=c==r.length)for(;c--&&(f=_(n[c],r[c],e,u)););return f}return t(n,function(n,t,o){return ir.call(o,t)?(c++,!(f=ir.call(r,t)&&_(n,r[t],e,u))&&W):void 0}),f&&t(r,function(n,r,t){return ir.call(t,r)?!(f=-1<--c)&&W:void 0}),f}function m(n){return typeof n=="function"}function d(n){return n?Sr[typeof n]:H}function b(n){return typeof n=="number"||fr.call(n)==br}function j(n){return typeof n=="string"||fr.call(n)==Ar}function w(n){for(var r=-1,t=Fr(n),e=t.length,u=Array(e);++r<e;)u[r]=n[t[r]];
return u}function A(n,r){var t=H;return typeof(n?n.length:0)=="number"?t=-1<M(n,r):e(n,function(n){return(t=n===r)&&W}),t}function x(n,r,t){var u=V;if(r=i(r,t),kr(n)){t=-1;for(var o=n.length;++t<o&&(u=!!r(n[t],t,n)););}else e(n,function(n,t,e){return!(u=!!r(n,t,e))&&W});return u}function E(n,r,t){var u=[];if(r=i(r,t),kr(n)){t=-1;for(var o=n.length;++t<o;){var a=n[t];r(a,t,n)&&u.push(a)}}else e(n,function(n,t,e){r(n,t,e)&&u.push(n)});return u}function O(n,r,t){var e;return r=i(r,t),S(n,function(n,t,u){return r(n,t,u)?(e=n,W):void 0
}),e}function S(n,r,t){if(r&&typeof t=="undefined"&&kr(n)){t=-1;for(var u=n.length;++t<u&&r(n[t],t,n)!==W;);}else e(n,r,t)}function N(n,r,t){var u=-1,o=n?n.length:0,a=Array(typeof o=="number"?o:0);if(r=i(r,t),kr(n))for(;++u<o;)a[u]=r(n[u],u,n);else e(n,function(n,t,e){a[++u]=r(n,t,e)});return a}function k(n,r,t){var u=-1/0,o=u;if(!r&&kr(n)){t=-1;for(var a=n.length;++t<a;){var f=n[t];f>o&&(o=f)}}else r=i(r,t),e(n,function(n,t,e){t=r(n,t,e),t>u&&(u=t,o=n)});return o}function F(n,r){return N(n,r+"")