Add checks back to isEqual and simplify checks in baseIsEqual.

This commit is contained in:
jdalton
2015-05-16 18:51:30 -07:00
parent b652fc7e1a
commit 0fa0397da2

View File

@@ -2282,16 +2282,11 @@
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/ */
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) { function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) { if (value === other) {
return true; return true;
} }
var valType = typeof value,
othType = typeof other;
// Exit early for unlike primitive values. // Exit early for unlike primitive values.
if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') || if ((typeof value != 'object' && typeof other != 'object') || value == null || other == null) {
value == null || other == null) {
// Return `false` unless both values are `NaN`. // Return `false` unless both values are `NaN`.
return value !== value && other !== other; return value !== value && other !== other;
} }
@@ -8775,7 +8770,18 @@
function isEqual(value, other, customizer, thisArg) { function isEqual(value, other, customizer, thisArg) {
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined; customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
var result = customizer ? customizer(value, other) : undefined; var result = customizer ? customizer(value, other) : undefined;
return result === undefined ? baseIsEqual(value, other, customizer) : !!result; if (result !== undefined) {
return !!result;
}
if (value === other) {
return true;
}
// Exit early for unlike primitive values.
if ((typeof value != 'object' && typeof other != 'object') || value == null || other == null) {
// Return `false` unless both values are `NaN`.
return value !== value && other !== other;
}
return baseIsEqual(value, other, customizer);
} }
/** /**