> Ha. I'm relatively new to JS and I though that ...
>
> var s_String = "bob";
>
> was just a shortcut for
>
> var s_LooksLikeAStringButDoesNotGoQuack = new String("bob");
>
> I always thought that internally they were the same thing.

I think a lot of people who used Javascript for a long time think the
same. Most languages they would be.

> It seems truely strange that they are not. If that is indeed the case.

> Yet I can call string methods on s_String just like I can on
> s_LooksLikeAStringButDoesNotGoQuack though.
>
> >>> s_String = 'bob';
> "bob"
> >>> s_String.toUpperCase()
> "BOB"
> >>> o_String = new String('bob')
> bob
> >>> o_String.toUpperCase()
> "BOB"
> >>> typeof o_String
> "object"
> >>> typeof s_String
>
> "string"
>
> There is a difference shown in FireBug in that o_String allows a
> breakdown of ...
>
> 0       "b"
> 1       "o"
> 2       "b"
>
> What does new String("bob") offer over normal "bob"?

As far as I know, nothing. Hence my assertion that Prototype should
treat object strings as if they were a normal string.

The Moz docs say in a few places things like:

"You should use string literals unless you specifically need to use a
String object, because String objects can have counterintuitive
behavior."
https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Predefined_Core_Objects/String_Object

But they don't give an example of this specific need. I dunno why
someone would call new String(), but if they *do* create strings that
way, IMO Javascript library code should treat them like native
strings.

--
Jim
blog:http://jimhigson.blogspot.com/
web:http://wikizzle.org
--~--~---------~--~----~------------~-------~--~----~
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