js> new String("a") == new String("a")
false
js> new Number(2) == new Number(2)
false
...
Which is due to the fact that if any of the operands is a JS
primitive type (i.e. string, number) then the other will be coerced
into a primitive value and then the equality among primitive values
will be used instead.
Yeah, it's bloody un-intuitive, but that's the way JS works. Nothing
you can do about it.
That makes sense. But what if one or both of the operands were Java
objects? e.g. replace the JS native String above with java.lang.String:
js> new java.lang.String("a") == new java.lang.String("a")
If this expression evaluated to true, it wouldn't violate JS equality
semantics, since JS values are not involved.
Groovy invokes the corresponding Java method on the left-hand operand.
So, if a Java object was on the left, equals() could be called, and if
a JS object was on the left, then JS reference equality could be used...
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino