开发者

Dynamic variables in JavaScript

  1. What is the use of Dynamic variables? Any scenarios?
  2. Can I attach this value to a TextField?

    var data = "testVariable";
    eval("var temp_" + data + "=123;");
    alert(temp_testV开发者_如何转开发ariable);
    


What is the use of Dyanmic variables? Any Scenarious

For when people haven't heard of objects or arrays.

Can i attach this value to a TextField?

Yes.


The answer to 2) is 'yes you can'.

However for 1), and overall, you probably shouldn't be using eval: Why is using the JavaScript eval function a bad idea?

As another comment and the currently upvoted answer says - either use arrays or a map.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜