[Javascript] dynamic var names
Terry Riegel
riegel at clearimageonline.com
Tue Aug 7 17:59:22 CDT 2007
I have always called this indirection, and have found several uses
for it. Not sure about js but I have used it on several server side
projects. Here is a quick outline of one such usage.
I had a user editable table that needed quite bit of processing for
each row in the table. I needed a way to cache the results. So I
created (via indirection) a variable whose name was the same as the
ID from each row.
So I needed a way to flag that a rows processing had been cached. I
created a variable whose name was the row ID. Since this ID was
assigned in the user editable table I had to use indirection to read/
write to the variable.
It is a little confusing, and Javascript may have better ways of
doing this.
Terry
On Aug 7, 2007, at 6:22 PM, Scott Reynen wrote:
> On Aug 7, 2007, at 3:18 PM, Troy III Ajnej wrote:
>
>> My understanding is that you are trying to asign a value to the
>> value!
>
> Not exactly. A dynamic variable name would assign a value to a
> variable with the name of a value. It's a pretty obscure concept,
> but in PHP, for example, you can do this like so:
>
> $variableName = 'foo';
> ${ $variableName } = 'bar';
> print( $foo ); // outputs 'bar'
>
> I've only ever found that useful in two contexts, neither of which
> appear to apply here: 1) obfuscation (i.e. making code more
> confusing than necessary) and 2) meta-programming (i.e. writing
> another programming language within PHP).
>
> Peace,
> Scott
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
More information about the Javascript
mailing list