It really depends on what they mean by "How to make comparison a == b to be true?"
If you're allowed to change the constructor, then you could make your constructor a singleton:
function F(){
if (!F.instance) {
F.instance = this;
} else {
return F.instance;
}
};
var a = new F();
var b = new F();
if (a === b) {
//they are the same
}
If they want you to keep everything as it is but have a comparision that contains a == b
then you could write the following:
if ("" + a == b) {
}
If they want to know methods of determine whether the two objects are instances of the same constructor function, then you could compare the constructor
property or the __proto__
property:
if (a.constructor === b.constructor) {
}
if (a.__proto__ === b.__proto__) {
}
If they want to know methods of dermine whether these two objects have the same properties, you can either compare their JSON string:
if (JSON.stringify(a) === JSON.stringify(b)) {
}
or you write a function that recursively compares all the properties in both objects (deep comparision).
And the most simple answer to the question "How to make comparison a == b to be true?":
var a = new F();
var b = new F();
b = a;
if (a === b) {
//surprise!!!
}