You are here: Re: Help with Javascript: naming variables using other variables « HTML « IT news, forums, messages
Re: Help with Javascript: naming variables using other variables

Posted by X l e c t r i c on 11/07/05 02:34

Jonathan=A0N.=A0Little wrote:

"You misunderstand, OP wants a variable-variable not a copy of a
variable with a different identifier, that is a variable with another
variable's name in it.

var hither=3D"Close by";
var yonder=3D"In the hills!";

Michael has the far better solution to avoid 'evail'

var global =3D this;
var whereAmI=3D"hither";
alert(global[whereAmI]); //displays 'Close by'
whereAmI=3D"yonder";
alert(global[whereAmI]); //now displays 'In the hills!'

--

Take care,

Jonathan"

Actually my point was about the unnecessary use of eval.

Michael and the other experts at comp.lang.javascript have helped me
many times, cwdjr too. And even though in this case his reply was more
directly related to and appropriate for the OP's question, who is to say
what is "far better". As we don't know the context with which this bit
of code will be used.

I could easily say that this:

var hither =3D "Close by";
var yonder =3D "In the hills!";
alert(hither);
alert(yonder);

is far more efficient and practical than what you offer, as the results
will be the same with a more simplistic approach. What I can't say
though is that this is the solution in any given situation without
knowing the application.

Later, Art.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация