0
Why False? / JS Objects
Can you explane why it is output "false"? function name(name) { this.name = name; } var obj1 = new name('Lucy'); var obj2 = new name('Lucy'); alert(obj1 == obj2) // false
5 Antworten
- 1
In JS, two objects are never equal to each other, even if they same properties.
http://ecma262-5.com/ELS5_HTML.htm#Section_11.9.3
Now, if everyone spent some time actually studying the basics this wouldn't happen.
+ 4
Because this is totally wrong.
I think you have confused classes and functions and contractor methods and everything!
My guess is you're trying to learn Java and JavaScript at the same time.
Anyways you are totally confused.
You're trying to make objects out of a function?! jeez...
0
Ali, it is example from JS challenge in that app. And why you laughting about making object throught function? It is from JS tutorial here. And you are wrong, I'm do not learning Java now. Just try to understand what is true and what is false in JS.
- 1
This is how the ECMAScript defined this language...
However there is one thing. In your code, if
var obj3 = obj2;
Then comparing obj2 and obj3 with == operator will result in true.
Also there are some methods to compare if two objects are prototype of same objects...
- 1
I don't think, this is a solitary case. This is a very common misunderstanding