Dynamic variables in JavaScript
- What is the use of Dynamic variables? Any scenarios?
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.
精彩评论