[Javascript] Defining the Name of a Variable at Runtime

gregory.john.toland at census.gov gregory.john.toland at census.gov
Sun Feb 10 16:59:01 CST 2002


Thanks to Dan and Jeff for their solutions.  The array method seemed to be
the easiest and more robust for future growth.  Thanks again!

Gregory J Toland
Sr. Systems Architect
CHM, Inc.
(301) 457-8058
tolan002 at census.gov


                                                                                                                                                
                    "Jeff Howden"                                                                                                               
                    <jeff at c4webdesign       To:     <javascript at LaTech.edu>                                                                     
                    .com>                   cc:                                                                                                 
                    Sent by:                Subject:     RE: [Javascript] Defining the Name of a Variable at Runtime                            
                    javascript-admin@                                                                                                           
                    LaTech.edu                                                                                                                  
                                                                                                                                                
                                                                                                                                                
                    02/06/2002 03:27                                                                                                            
                    PM                                                                                                                          
                    Please respond to                                                                                                           
                    javascript                                                                                                                  
                                                                                                                                                
                                                                                                                                                




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/



_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript






More information about the Javascript mailing list