On Fri, Feb 4, 2011 at 7:13 PM, Michael Haufe (TNO) <[email protected]
> wrote:
>
> If you want a consistent way to evaluate and "enforce" the type of
> individual values through the instanceof operator, this would be the
> approach to use.
>
In that case, you'll rarely have a meaningful class that contains only a
single
numeric value, and even if you do, you can make a class for it instead of
using
a generic wrapper class.
> new String() can also have some utility as with it you could simulate
> Mozilla's string indexing:
>
> var foo = new String("myString"); //where the constructor creates
> numeric members
>
That would then not be the default String constructor. I.e., you would have
a new class for that.
>
> foo[2]; //"S"
>
> Not saying that these are necessarily wise decisions, but they are
> examples of possible uses for primitive wrappers.
It's generally faster to access the characters directly on the primitive
string value, e.g.,
var s = "myString";
alert(s[2]); // 'S'
instead of
var s = new String("myString");
alert(s[2]); // 'S'
so I would prefer to not generally wrap strings just to support old
browsers.
/L
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]