| comments | Javascript source | Execution result in your current browser |
|---|---|---|
| two objects were not born equal | var obj1=new Object();
var obj2=new Object();
document.write("obj1==obj2?"+(obj1==obj2));
document.write("<br/>obj1, type="+typeof(obj1)+" value: "+obj1);
document.write("<br/>obj2, type="+typeof(obj2)+" value: "+obj2);
var bothequal=typeof(obj1) == typeof(obj2) && (obj1==obj2);
document.write("<br/>are typeof and value the same? "+bothequal);
document.write("<br/>obj1===obj2?"+(obj1===obj2));
|
|
| how to make them equal? valueOf doesn't do the trick |
function MyObjectType(id) {
this.id=id;
}
MyObjectType.prototype.valueOf=function() {return this.id;}
var object1=new MyObjectType(8);
var object2=new MyObjectType(8);
document.write("object1==object2? "+(object1==object2));
|
|