Re: Using a string as a variable name
From: Lasse Reichstein Nielsen (lrn_at_hotpop.com)
Date: 06/22/04
- Previous message: aklj: "Re: Using a string as a variable name"
- In reply to: aklj: "Re: Using a string as a variable name"
- Next in thread: Lee: "Re: Using a string as a variable name"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Jun 2004 18:00:47 +0200
"=?Utf-8?B?YWtsag==?=" <aklj@discussions.microsoft.com> writes:
> I've only just started to seriously use scripting with CSS and what
> I'm trying to do is pretty complex and hard to explain clearly.
Experience tells me that being "hard to explain clearly" usually means
that you don't have a clear understanding of it yourself. That is very
likely if you are a recent stater with DHTML, since it isn't as easy
as it might look :)
> var nTabNine = 9;
> var strVar = "nTab"+"Nine";
> var nNewVar = &strVar; // nNewVar = 9 if & used like FoxPro
>
> Trust me, this is useful.
I'll still maintain that it is not the best way to achieve that
effect, and something I would recommend against getting as a habit.
Perhaps it is because I was raised on compiled languages, and this
construction only works in an interpreted language ... or maybe that's
the reason that I just don't like mixing compile time and run
time. The value of strVar is a run time value, whereas variable
resolution should (IMO) be compile time ... I just think it's asking
for trouble to mix the two.
But I'm sometimes too much of a language theoretician :)
> I was sure modern core languages would allow you to do this through
> a simple operator/command (like &) but haven't found a way yet or
> even know if it can be done although I take your point about
> window[] when using JScript and DOM.
Only interpreted languages would be able to do this, since compiled
languages don't remember the variable names for run time.
ECMAScript has one operation that can turn a variable name into its
value: eval. However, that is far too big a cannon to use for this,
and it is prone to misfiring if not handled carefully. Using the
global object (aka "window") only works for global variables, not
local.
/L
-- Lasse Reichstein Nielsen - lrn@hotpop.com DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'
- Previous message: aklj: "Re: Using a string as a variable name"
- In reply to: aklj: "Re: Using a string as a variable name"
- Next in thread: Lee: "Re: Using a string as a variable name"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|