isEqual Underscore.js. " , , ". . :
_.isEqual = function(a, b) {
if (a === b) return true;
var atype = typeof(a), btype = typeof(b);
if (atype != btype) return false;
if (a == b) return true;
if ((!a && b) || (a && !b)) return false;
if (a._chain) a = a._wrapped;
if (b._chain) b = b._wrapped;
if (a.isEqual) return a.isEqual(b);
if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
if (_.isNaN(a) && _.isNaN(b)) return false;
if (_.isRegExp(a) && _.isRegExp(b))
return a.source === b.source &&
a.global === b.global &&
a.ignoreCase === b.ignoreCase &&
a.multiline === b.multiline;
if (atype !== 'object') return false;
if (a.length && (a.length !== b.length)) return false;
var aKeys = _.keys(a), bKeys = _.keys(b);
if (aKeys.length != bKeys.length) return false;
for (var key in a) if (!(key in b) || !_.isEqual(a[key], b[key])) return false;
return true;
};
See the Underscore.js source code to see the rest of the functions used by this.
It’s easy to overlook some extreme cases, so I would recommend using well-tested code like this instead of reinventing the wheel.
source
share