Rich MacDonald wrote:
[color=blue]
> Short question: Is there any limit to the length of a single line in
> javascript?[/color]
Hmmmm, good question.
[color=blue]
> (Not in the FAQ; came up short in google, and haven't found the really good
> references yet.)
>
> Long question: I'm writing a n-depth hierarchical select function and I
> need to seed the options data. I could do something like:
>
> 1)
> data = new Array(1, 2, 3);
> data_0 = new Array(11, 12, 13);
> data_0_0 = new Array(111, 112, 113);
> etc[/color]
use an Object instead.
var data = new Object();
data.1 = new Object(11,12,13);
data.1.11 = new Object(111,112,113);
And so on. There are better constructs for doing that, such as the one
below, but it hinders readability when debugging.
[color=blue]
> Or 2)
> data = new Array(1, new Array(11, new Array(111, 112, 113), 12, 13), 2, 3);
>
> This is going to be auto-generated stuff, so the unreadability of the 2nd
> approach doesn't bother me. So my prime concern is which is the
> better/faster approach. I'd benchmark the two, but I first want to make
> sure the 2nd approach is ok. If the options are lengthy, then the line in
> the 2nd approach could be very long.[/color]
Do it the first way. Even if no other reason than readability to debug
any errors until its error free. It also remedies 99% of the problem
with line/variable lengths.
[color=blue]
> P.S. An answer such as: "javascript is fast enough on the client that this
> is a silly issue to worry about" is a good one, if its true.[/color]
Javascript speed is directly dependent on the code though :)
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly