问题
Say I have the following objects in Javascript:
var a = { xxx: 33 };
var b = { xxx: 33 };
var c;
c = a;
What is the Javascript test that will tell me whether I am dealing with the same object instance? In other words, it should return false for a and b, b and c, but true for a and c.
回答1:
You just need this
if(c == a) {
// same instance
}
a == b
and b == c
will return false
回答2:
Just a standard equality test:
( a == c ) // true
( a == b ) // false
来源:https://stackoverflow.com/questions/26214966/how-to-test-same-object-instance-in-javascript