|
Posted by Michael Winter on 11/06/05 19:31
On 06/11/2005 16:54, Jonathan N. Little wrote:
[snip]
> var foo="Value of Foo";
> var bar="foo";
> alert( "foo=" + foo + "\n evail of bar=" + eval(bar) );
The eval function is evil. It's use is rarely ever necessary.
ECMAScript provides bracket notation as an alternative to dot notation
property accessors. This form allows any expression, including function
calls and variables, which will be evaluated and type-converted to a
string. The result will then be used as the property name.
Global variables, such as foo and bar, above, are members of the global
object:
var global = this; /* The window identifier also refers
* to the global object in browsers.
*/
alert(global[bar]); /* 'Value of Foo' */
See Bracket Notation[1] in the c.l.javascript FAQ notes.
Mike
[1] <http://www.jibbering.com/faq/faq_notes/square_brackets.html>
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Navigation:
[Reply to this message]
|