[Javascript] dynamic var names

Michael Borchers list at tridemail.de
Tue Aug 7 07:16:07 CDT 2007


----- Original Message ----- 
From: "David Dorward" <david at dorward.me.uk>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Tuesday, August 07, 2007 1:39 PM
Subject: Re: [Javascript] dynamic var names


> On 7 Aug 2007, at 10:12, Michael Borchers wrote:
>> I dynamically create a name for a var, let's say
>> var myDynVar    = 'foo';
>> Now I want to fill (var) foo with a value f.e. 'bar', so the next  
>> time I
>> alert(foo)    results in => bar;
> 
> Create an object. Use the myObject[myDunVar] property. (While you  
> could use the window object directly - don't, its dirty, unintuitive  
> and painful to maintain).
> 
>> I tried several combinations with eval()
> 
> Keep away from eval(), its almost always the wrong solution to any  
> problem.
> 
> -- 
> David Dorward

Thanks David, I see, this is the only possibilty in javascript.

by the way: i only use eval() for getting JSON data from my AJAX requests:)




More information about the Javascript mailing list