I have a quick question on why my function is returning false, when I expect it to be returning true.
function isEquivalent(a, b) {
// arrays of property names
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
// If their property lengths are different, they're different objects
if (aProps.length != bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var propName = aProps[i];
// If the values of the property are different, not equal
if (a[propName] !== b[propName]) {
return false;
}
}
// If everything matched, correct
return true;
}
var obj1 = {'prop1': 'test','prop2': function (){} };
var obj2 = {'prop1': 'test','prop2': function (){} };
isEquivalent(obj1,obj2); // returns false
the two objects(obj1, obj2) are perfectly matched but Why is return value false?
Could someone help me perfectly understand this function?