From 9dfa2609bed5a33b19e84db073cf53bf9be7b66c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 8 Feb 2013 22:47:43 -0800 Subject: [PATCH] Cleanup `_.isEqual`. Former-commit-id: 83dd17b62fc86b870ca44aa4a54387343fd14cb2 --- dist/lodash.compat.js | 20 ++++++++++---------- dist/lodash.compat.min.js | 14 +++++++------- dist/lodash.js | 20 ++++++++++---------- dist/lodash.min.js | 10 +++++----- dist/lodash.underscore.js | 2 -- doc/README.md | 4 ++-- lodash.js | 20 ++++++++++---------- 7 files changed, 44 insertions(+), 46 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index b16acfc9a..69c3cc35b 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -627,7 +627,7 @@ var length = props.length, result = false; while (length--) { - if (!(result = isEqual(object[props[length]], func[props[length]], undefined, undefined, indicatorObject))) { + if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) { break; } } @@ -1411,8 +1411,6 @@ * @param {Mixed} b The other value to compare. * @param {Function} [callback] The function to customize comparing values. * @param {Mixed} [thisArg] The `this` binding of `callback`. - * @param- {Object} [whereIndicator] Internally used to indicate that when - * comparing objects, `a` has at least the properties of `b`. * @param- {Object} [stackA=[]] Internally used track traversed `a` objects. * @param- {Object} [stackB=[]] Internally used track traversed `b` objects. * @returns {Boolean} Returns `true`, if the values are equvalent, else `false`. @@ -1439,8 +1437,10 @@ * }); * // => true */ - function isEqual(a, b, callback, thisArg, whereIndicator, stackA, stackB) { - if (callback) { + function isEqual(a, b, callback, thisArg, stackA, stackB) { + // used to indicate that when comparing objects, `a` has at least the properties of `b` + var whereIndicator = callback == indicatorObject; + if (callback && !whereIndicator) { callback = typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg, 2); var result = callback(a, b); if (typeof result != 'undefined') { @@ -1503,7 +1503,7 @@ if (!isArr) { // unwrap any `lodash` wrapped values if (a.__wrapped__ || b.__wrapped__) { - return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, undefined, whereIndicator, stackA, stackB); + return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, thisArg, stackA, stackB); } // exit for functions and DOM nodes if (className != objectClass || (noNodeClass && (isNode(a) || isNode(b)))) { @@ -1544,12 +1544,12 @@ if (isArr) { // compare lengths to determine if a deep comparison is necessary size = b.length; - result = whereIndicator == indicatorObject || size == a.length; + result = whereIndicator || size == a.length; if (result) { // deep compare the contents, ignoring non-numeric properties while (size--) { - if (!(result = isEqual(a[size], b[size], callback, undefined, whereIndicator, stackA, stackB))) { + if (!(result = isEqual(a[size], b[size], callback, thisArg, stackA, stackB))) { break; } } @@ -1563,11 +1563,11 @@ // count the number of properties. size++; // deep compare each property value. - return (result = hasOwnProperty.call(a, key) && isEqual(a[key], value, callback, undefined, whereIndicator, stackA, stackB)); + return (result = hasOwnProperty.call(a, key) && isEqual(a[key], value, callback, thisArg, stackA, stackB)); } }); - if (result && whereIndicator != indicatorObject) { + if (result && !whereIndicator) { // ensure both objects have the same number of properties forIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) { diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index a085b4f1f..14211df2c 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,16 +5,16 @@ * Underscore.js 1.4.4 underscorejs.org/LICENSE */ ;(function(n,t){function r(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,void 0):new r(n)}function e(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||it);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(ne;e++)r+="i='"+t.k[e]+"';if(","constructor"==t.k[e]&&(r+="!(f&&f.prototype===m)&&"),r+="h.call(m,i)){"+t.h+"}"; +}return re;e++)r+="i='"+t.k[e]+"';if(","constructor"==t.k[e]&&(r+="!(f&&f.prototype===m)&&"),r+="h.call(m,i)){"+t.h+"}"; return(t.b||t.i)&&(r+="}"),r+=t.c+";return t",Function("e,h,j,k,l,q,o","return function("+n+"){"+r+"}")(f,Ot,h,lr,A,rr,Rt)}function c(n){return"\\"+er[n]}function l(n){return sr[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);++er?$t(0,u+r):r)||0,typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):z(n,t,r)):fr(n,function(n){return++er?$t(0,u+r):r)||0,typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):z(n,t,r)):fr(n,function(n){return++eo&&(o=a)}}else t=!t&&A(n)?u:f(t,r),fr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function I(n,t,r,e){var u=3>arguments.length;if(t=f(t,e,4),lr(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof o!="number")var a=pr(n),o=a.length;else Xt&&A(n)&&(u=n.split(""));return t=f(t,e,4),$(n,function(n,e,f){e=a?a[--o]:--o,r=i?(i=W,u[e]):t(r,u[e],e,f)}),r}function B(n,t,r){var e;if(t=f(t,r),lr(n)){r=-1;for(var u=n.length;++rr?$t(0,u+r):r||0)-1;else if(r)return e=K(n,t),n[e]===t?e:-1;for(;++e true */ - function isEqual(a, b, callback, thisArg, whereIndicator, stackA, stackB) { - if (callback) { + function isEqual(a, b, callback, thisArg, stackA, stackB) { + // used to indicate that when comparing objects, `a` has at least the properties of `b` + var whereIndicator = callback == indicatorObject; + if (callback && !whereIndicator) { callback = typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg, 2); var result = callback(a, b); if (typeof result != 'undefined') { @@ -1360,7 +1360,7 @@ if (!isArr) { // unwrap any `lodash` wrapped values if (a.__wrapped__ || b.__wrapped__) { - return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, undefined, whereIndicator, stackA, stackB); + return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, thisArg, stackA, stackB); } // exit for functions and DOM nodes if (className != objectClass) { @@ -1401,12 +1401,12 @@ if (isArr) { // compare lengths to determine if a deep comparison is necessary size = b.length; - result = whereIndicator == indicatorObject || size == a.length; + result = whereIndicator || size == a.length; if (result) { // deep compare the contents, ignoring non-numeric properties while (size--) { - if (!(result = isEqual(a[size], b[size], callback, undefined, whereIndicator, stackA, stackB))) { + if (!(result = isEqual(a[size], b[size], callback, thisArg, stackA, stackB))) { break; } } @@ -1420,11 +1420,11 @@ // count the number of properties. size++; // deep compare each property value. - return (result = hasOwnProperty.call(a, key) && isEqual(a[key], value, callback, undefined, whereIndicator, stackA, stackB)); + return (result = hasOwnProperty.call(a, key) && isEqual(a[key], value, callback, thisArg, stackA, stackB)); } }); - if (result && whereIndicator != indicatorObject) { + if (result && !whereIndicator) { // ensure both objects have the same number of properties forIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) { diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 0ba3fc17a..586984e03 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,13 +5,13 @@ * Underscore.js 1.4.4 underscorejs.org/LICENSE */ ;(function(n,t){function r(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,void 0):new r(n)}function e(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||Y);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(nr?0:r);++er?xt(0,u+r):r)||0,typeof u=="number"?o=-1<(x(n)?n.indexOf(t,r):M(n,t,r)):Gt(n,function(n){return++eo&&(o=a)}}else t=!t&&x(n)?u:f(t,r),Gt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function F(n,t,r,e){var u=3>arguments.length;if(t=f(t,e,4),Lt(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++o ### `_.isEqual(a, b [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1449 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1447 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. If `callback` is passed, it will be executed to compare values. If `callback` returns `undefined`, comparisons will be handled by the method instead. The `callback` is bound to `thisArg` and invoked with two arguments; *(a, b)*. @@ -3417,7 +3417,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` # [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4788 "View in source") [Ⓣ][1] -The opposite of `_.escape`, this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. +The opposite of `_.escape`, this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. #### Arguments 1. `string` *(String)*: The string to unescape. diff --git a/lodash.js b/lodash.js index f98ea51ea..0ed44ae6b 100644 --- a/lodash.js +++ b/lodash.js @@ -634,7 +634,7 @@ var length = props.length, result = false; while (length--) { - if (!(result = isEqual(object[props[length]], func[props[length]], undefined, undefined, indicatorObject))) { + if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) { break; } } @@ -1418,8 +1418,6 @@ * @param {Mixed} b The other value to compare. * @param {Function} [callback] The function to customize comparing values. * @param {Mixed} [thisArg] The `this` binding of `callback`. - * @param- {Object} [whereIndicator] Internally used to indicate that when - * comparing objects, `a` has at least the properties of `b`. * @param- {Object} [stackA=[]] Internally used track traversed `a` objects. * @param- {Object} [stackB=[]] Internally used track traversed `b` objects. * @returns {Boolean} Returns `true`, if the values are equvalent, else `false`. @@ -1446,8 +1444,10 @@ * }); * // => true */ - function isEqual(a, b, callback, thisArg, whereIndicator, stackA, stackB) { - if (callback) { + function isEqual(a, b, callback, thisArg, stackA, stackB) { + // used to indicate that when comparing objects, `a` has at least the properties of `b` + var whereIndicator = callback == indicatorObject; + if (callback && !whereIndicator) { callback = typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg, 2); var result = callback(a, b); if (typeof result != 'undefined') { @@ -1510,7 +1510,7 @@ if (!isArr) { // unwrap any `lodash` wrapped values if (a.__wrapped__ || b.__wrapped__) { - return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, undefined, whereIndicator, stackA, stackB); + return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, thisArg, stackA, stackB); } // exit for functions and DOM nodes if (className != objectClass || (noNodeClass && (isNode(a) || isNode(b)))) { @@ -1551,12 +1551,12 @@ if (isArr) { // compare lengths to determine if a deep comparison is necessary size = b.length; - result = whereIndicator == indicatorObject || size == a.length; + result = whereIndicator || size == a.length; if (result) { // deep compare the contents, ignoring non-numeric properties while (size--) { - if (!(result = isEqual(a[size], b[size], callback, undefined, whereIndicator, stackA, stackB))) { + if (!(result = isEqual(a[size], b[size], callback, thisArg, stackA, stackB))) { break; } } @@ -1570,11 +1570,11 @@ // count the number of properties. size++; // deep compare each property value. - return (result = hasOwnProperty.call(a, key) && isEqual(a[key], value, callback, undefined, whereIndicator, stackA, stackB)); + return (result = hasOwnProperty.call(a, key) && isEqual(a[key], value, callback, thisArg, stackA, stackB)); } }); - if (result && whereIndicator != indicatorObject) { + if (result && !whereIndicator) { // ensure both objects have the same number of properties forIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) {