I understand the construction function is a special function returning a object. But
> Animal = function (){this.species='animal'}
> a=new Animal()
> b={species:'animal'}
> a==b
==> false
Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Comparisons like that are not “deep” comparisons. Either “a” and “b” refer to the exact same object or they don’t.
To put it another way, by comparing the two variables you’re comparing references to objects, not the objects themselves.
edit — there’s a difference between primitive types (booleans, numbers, strings) and object references. Like I said, what you’ve got in your question is a pair of object references. Two object references are considered equal if they refer to the same object. In your case, they don’t. They’re two different objects that happen to have the same property with the same value. The properties of the objects do not play a part in the
==comparison because that’s simply how the language is defined to work.