Skip to content

Instantly share code, notes, and snippets.

@dz
Forked from gjcourt/JSON Object Equality.js
Created February 25, 2011 04:41
Show Gist options
  • Save dz/843368 to your computer and use it in GitHub Desktop.
Save dz/843368 to your computer and use it in GitHub Desktop.
/**
* not so simple check for object equality
*/
var equal = function(a, b) {
function check(a, b) {
for (var attr in a) {
if (a.hasOwnProperty(attr) && b.hasOwnProperty(attr)) {
if (a[attr] != b[attr]) {
switch (a[attr].constructor) {
case Object:
return equal(a[attr], b[attr]);
case Function:
if (a[attr].toString() != b[attr].toString()) {
return false;
}
break;
default:
return false;
}
}
} else {
return false;
}
}
return true;
};
return check(a, b) && check(b, a);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment