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 sagejoshua on 10/07/17 11:31

On Mon, 07 Nov 2005 13:53:53 GMT, Michael Winter
<m.winter@blueyonder.co.uk> wrote:


>To elaborate on what Leif wrote, the variable variable constructed above
> is made possible through string concatenation, similar to
>
> var variable = 'foo';
>
> this[variable + 'bar'] = 'Great!'; /* foobar = 'Great!'; */
>

Ah, it all starts to make sense now. You can refer to any variable
using the "global array" this[whatever], and whatever is in the
brackets will be parsed. Very nice tool. My question is, what's so
evil about eval()?

>in ECMAScript. However, rather than using a string literal, the OP has
>written in bar what would normally considered a constant. Indeed, if
>STRICT notices are enabled in PHP, this will be reported in the error log.
>
>It would be better written as:
>
> <?php
> $variable = 'foo';
> ${$variable . 'bar'} = 'Great!';
> print $foobar; /* Great! */
> ?>

Yeah, you're right. I was just being sloppy.


Thanks for all the help.
Josh

 

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

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