From 0a7fc6c48ccc5b383fda64e0dd028f8724c3cbb7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 3 Jul 2014 12:26:47 -0700 Subject: [PATCH] Cleanup error object fork in `baseIsEqual`. --- lodash.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lodash.js b/lodash.js index d0719a237..8adf217c5 100644 --- a/lodash.js +++ b/lodash.js @@ -1964,28 +1964,31 @@ valIsArg = isArguments(value); othIsArg = isArguments(other); } - var hasValCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'), - hasOthCtor = !othIsArg && hasOwnProperty.call(other, 'constructor'); - - if (hasValCtor != hasOthCtor) { - return false; - } - if (!hasValCtor) { - // in older versions of Opera, `arguments` objects have `Array` constructors - var valCtor = valIsArg ? Object : value.constructor, - othCtor = othIsArg ? Object : other.constructor; + // in older versions of Opera, `arguments` objects have `Array` constructors + var valCtor = valIsArg ? Object : value.constructor, + othCtor = othIsArg ? Object : other.constructor; + if (isErr) { // error objects of different types are not equal - if (isErr && valCtor.prototype.name != othCtor.prototype.name) { + if (valCtor.prototype.name != othCtor.prototype.name) { return false; } - // non `Object` object instances with different constructors are not equal - if (valCtor != othCtor && - !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && - ('constructor' in value && 'constructor' in other) - ) { + } else { + var valHasCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'), + othHasCtor = !othIsArg && hasOwnProperty.call(other, 'constructor'); + + if (valHasCtor != othHasCtor) { return false; } + if (!valHasCtor) { + // non `Object` object instances with different constructors are not equal + if (valCtor != othCtor && + !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && + ('constructor' in value && 'constructor' in other) + ) { + return false; + } + } } var valProps = isErr ? ['message', 'name'] : keys(value), othProps = isErr ? valProps : keys(other);