1 var keys = require('./keys');
3 /** Used to compose bitmasks for comparison styles. */
4 var PARTIAL_COMPARE_FLAG = 2;
6 /** Used for built-in method references. */
7 var objectProto = Object.prototype;
9 /** Used to check objects for own properties. */
10 var hasOwnProperty = objectProto.hasOwnProperty;
13 * A specialized version of `baseIsEqualDeep` for objects with support for
14 * partial deep comparisons.
17 * @param {Object} object The object to compare.
18 * @param {Object} other The other object to compare.
19 * @param {Function} equalFunc The function to determine equivalents of values.
20 * @param {Function} customizer The function to customize comparisons.
21 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
23 * @param {Object} stack Tracks traversed `object` and `other` objects.
24 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
26 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
27 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
28 objProps = keys(object),
29 objLength = objProps.length,
30 othProps = keys(other),
31 othLength = othProps.length;
33 if (objLength != othLength && !isPartial) {
36 var index = objLength;
38 var key = objProps[index];
39 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
43 // Assume cyclic values are equal.
44 var stacked = stack.get(object);
45 if (stacked && stack.get(other)) {
46 return stacked == other;
49 stack.set(object, other);
50 stack.set(other, object);
52 var skipCtor = isPartial;
53 while (++index < objLength) {
54 key = objProps[index];
55 var objValue = object[key],
56 othValue = other[key];
59 var compared = isPartial
60 ? customizer(othValue, objValue, key, other, object, stack)
61 : customizer(objValue, othValue, key, object, other, stack);
63 // Recursively compare objects (susceptible to call stack limits).
64 if (!(compared === undefined
65 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
71 skipCtor || (skipCtor = key == 'constructor');
73 if (result && !skipCtor) {
74 var objCtor = object.constructor,
75 othCtor = other.constructor;
77 // Non `Object` object instances with different constructors are not equal.
78 if (objCtor != othCtor &&
79 ('constructor' in object && 'constructor' in other) &&
80 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
81 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
85 stack['delete'](object);
86 stack['delete'](other);
90 module.exports = equalObjects;