How to test same object instance in Javascript?

前端 未结 2 1781
孤独总比滥情好
孤独总比滥情好 2021-02-11 19:17

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

相关标签:
2条回答
  • 2021-02-11 19:34

    Just a standard equality test:

    ( a == c ) // true
    ( a == b ) // false
    
    0 讨论(0)
  • 2021-02-11 19:39

    You just need this

    if(c == a) {
       // same instance
    }
    

    a == b and b == c will return false

    0 讨论(0)
提交回复
热议问题