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

15th Dec 2016, 12:50 PM
LoooooooL
LoooooooL - avatar
5 Réponses
- 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.
15th Dec 2016, 1:03 PM
Rishi Anand
Rishi Anand - avatar
+ 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...
15th Dec 2016, 1:10 PM
Alireza M
Alireza M - avatar
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.
15th Dec 2016, 1:14 PM
LoooooooL
LoooooooL - avatar
- 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...
15th Dec 2016, 1:10 PM
Rishi Anand
Rishi Anand - avatar
- 1
I don't think, this is a solitary case. This is a very common misunderstanding
15th Dec 2016, 1:11 PM
Rishi Anand
Rishi Anand - avatar