B
Bart Lateur
A word of warning for you people who write their scripts and test them
on a single platform. Even in this day and age, when portability of
Javascript is a lot higher than it used to be, it might still bite you
in the arse.
For example. Try to run this in Firefox:
s = "ACE"; alert(s[1] );
You'll see a textbox showing a "C", the second character from the
string. So, Firefox treats a string, in traditional C manner, (also) as
an array of characters.
But! In MSIE (5.5, 6 and 7), this displays "undefined". So, MSIE does
not treat a string (also) as an array of characters.
n.b. I've tried to run this in Opera 9, and it displays a "C", too.
As a portable solution, use
s.substring(i, 1)
instead of
s
As a question to the experts: do you think s, with s a string,
*should* return the character in position i, from a theoretical point of
view?
on a single platform. Even in this day and age, when portability of
Javascript is a lot higher than it used to be, it might still bite you
in the arse.
For example. Try to run this in Firefox:
s = "ACE"; alert(s[1] );
You'll see a textbox showing a "C", the second character from the
string. So, Firefox treats a string, in traditional C manner, (also) as
an array of characters.
But! In MSIE (5.5, 6 and 7), this displays "undefined". So, MSIE does
not treat a string (also) as an array of characters.
n.b. I've tried to run this in Opera 9, and it displays a "C", too.
As a portable solution, use
s.substring(i, 1)
instead of
s
As a question to the experts: do you think s, with s a string,
*should* return the character in position i, from a theoretical point of
view?