On Sep 3, 1:56 am, enigment <enigm...@gmail.com> wrote:
> Hmmm, even outside the indexOf() question, this is a bit creepy to me.
> I hadn't previously tested, but these are all true, at least in
> Firefox 3.5 and IE8:
[...]
>         new String("mpg") !== new String("mpg")
>         new String("mpg") != new String("mpg")

Because that is comparing two different objects, which can never be
equal.

[...]
>         new Number(1) != new Number(1)

Same here.

>
>         [] != []
>         new Array() != new Array()
>         new Array() != []
>
>         new Object() != {}

And again. Object literal syntax is identical to using the new
operator, only faster.


> Is it an identity test -- is it the same actual object? -- maybe
> coupled with the way various types of data are stored internally? It
> looks like once the string "mpg" has been created, another literal
> "msg" is the same, but a new String object containing the same literal
> is not. The analogous tests with Number, Array, and Object values
> indicate somewhat different behavior, but since it's consistent across
> IE and Firefox, it seems inherent in the language.
>
> Can anyone explain, not *how* this actually works, but the logic
> behind it?

That is how it is specified by the ECMA-262 specification, every
object has a unique identity.


--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to