> http://dev.opera.com/articles/view/48/
>
> I didn't know that this:
> var s = new String('0123456789');
> for( var i = 0; i < s.length; i++ ) {
> s.charAt(i);
> }
>
> [is faster than?--dm] this:
> var s = '0123456789';
> for( var i = 0; i < s.length; i++ ) {
> s.charAt(i);
> }
> because of the implicit object conversion involved.
Optimizations based on Opera may go the wrong way for a majority of users.
For example, here are some hard millisecond numbers from a test of that
example:
Object string
Opera 9: 344 406
FF 1.5: 1859 2703
IE6: 640 453
So, it's blazingly fast either way in Opera, faster to use a string in IE,
and a choice between slow and horribly slow in Firefox. Perhaps a difference
in memory usage would justify it if the string was extremely long?
Object wrappers are a minefield because they sometimes don't behave the same
as their primitive type. For example, eval() won't work if called with a
"new String" argument, and "new Boolean(false)" evaluates to TRUE in a
conditional context because it's an object.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/