Reimplemented _.isEqual tests and patch in a fresh branch.

This commit is contained in:
Kevin Malakoff
2011-10-06 15:50:51 +02:00
parent 0ed3b65df1
commit f2a64227fd
2 changed files with 61 additions and 4 deletions

View File

@@ -635,7 +635,15 @@
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
if (a === b) return a !== 0 || 1 / a == 1 / b;
// A strict comparison is necessary because `null == undefined`.
if (a == null) return a === b;
if ((a == null) || (b == null)) return a === b;
// Either one is undefined
if ((a === void 0) || (b === void 0)) return false;
// Unwrap any wrapped objects.
if (a._chain) a = a._wrapped;
if (b._chain) b = b._wrapped;
// One of them implements an isEqual()
if (a.isEqual) return a.isEqual(b);
if (b.isEqual) return b.isEqual(a);
// Compare object types.
var typeA = typeof a;
if (typeA != typeof b) return false;
@@ -667,9 +675,6 @@
}
// Ensure that both values are objects.
if (typeA != 'object') return false;
// Unwrap any wrapped objects.
if (a._chain) a = a._wrapped;
if (b._chain) b = b._wrapped;
// Invoke a custom `isEqual` method if one is provided.
if (_.isFunction(a.isEqual)) return a.isEqual(b);
// Assume equality for cyclic structures. The algorithm for detecting cyclic structures is