-
-
Save dz/843368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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