[Javascript] Defining the Name of a Variable at Runtime
Jeff Howden
jeff at c4webdesign.com
Wed Feb 6 14:27:44 CST 2002
greg,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: gregory.john.toland at census.gov
>
> Is it possible to define the name of a variable at
> runtime? I would like to create variables a1...a100
> like....
>
> eval( "a" + i ) = new Image( 214, 39 );
>
> Is this possible?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
sure, but not with the eval() on the left side of the assignment operator.
why would you want to do it this way, as opposed to just using an array
though?
a = new Array();
a[0] = new Image(214, 39);
if you really want to use dynamic variable names, then create them without
the eval() function by referencing them as properties of the "self" object
(which they are anyway).
self['a' + i] = new Image(214, 39);
good luck,
.jeff
http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/
More information about the Javascript
mailing list