Trying to make a simple deep comparison function and noticed that this block of code was returning false when it should be true. Added the console logs to find the flaw.
for(var prop in obj1){
if(obj1[prop] !== obj2[prop]){
console.log("obj1." + prop + " = " + JSON.stringify(obj1[prop]));
console.log("obj2." + prop + " = " + JSON.stringify(obj2[prop]));
return false;
}
}
var obj = {here: {is: "an"}, object: 2};
console.log(deepEqual(obj, {here: 1, object: 2}));
// → false
console.log(deepEqual(obj, {here: {is: "an"}, object: 2}));
// → true
results are
obj1.here = {"is":"an"}
obj2.here = 1
false
obj1.here = {"is":"an"}
obj2.here = {"is":"an"}
false
So I can tell the for... in prop method seems to be working because it's comparing 'here' for example. This is good. I think they're equal in the second console.log, so I think the answer is to use a different way of comparing them, because it's still evaluating them by reference possibly?