1 var baseHas = require('./_baseHas'),
2 keys = require('./keys');
4 /** Used to compose bitmasks for comparison styles. */
5 var PARTIAL_COMPARE_FLAG = 2;
8 * A specialized version of `baseIsEqualDeep` for objects with support for
9 * partial deep comparisons.
12 * @param {Object} object The object to compare.
13 * @param {Object} other The other object to compare.
14 * @param {Function} equalFunc The function to determine equivalents of values.
15 * @param {Function} [customizer] The function to customize comparisons.
16 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
17 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
18 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
20 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
21 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
22 objProps = keys(object),
23 objLength = objProps.length,
24 othProps = keys(other),
25 othLength = othProps.length;
27 if (objLength != othLength && !isPartial) {
30 var index = objLength;
32 var key = objProps[index];
33 if (!(isPartial ? key in other : baseHas(other, key))) {
37 // Assume cyclic values are equal.
38 var stacked = stack.get(object);
40 return stacked == other;
43 stack.set(object, other);
45 var skipCtor = isPartial;
46 while (++index < objLength) {
47 key = objProps[index];
48 var objValue = object[key],
49 othValue = other[key];
52 var compared = isPartial
53 ? customizer(othValue, objValue, key, other, object, stack)
54 : customizer(objValue, othValue, key, object, other, stack);
56 // Recursively compare objects (susceptible to call stack limits).
57 if (!(compared === undefined
58 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
64 skipCtor || (skipCtor = key == 'constructor');
66 if (result && !skipCtor) {
67 var objCtor = object.constructor,
68 othCtor = other.constructor;
70 // Non `Object` object instances with different constructors are not equal.
71 if (objCtor != othCtor &&
72 ('constructor' in object && 'constructor' in other) &&
73 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
74 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
78 stack['delete'](object);
82 module.exports = equalObjects;