开发者

How do I dynamically create a _global variable? Like: _global.eval("var" + i)

开发者 https://www.devze.com 2023-02-13 12:37 出处:网络
I开发者_如何学Python\'m pretty sure eval doesn\'t work this way, but it gets the idea across. I\'m trying to dynamically create global variables; here\'s my code:

I开发者_如何学Python'm pretty sure eval doesn't work this way, but it gets the idea across. I'm trying to dynamically create global variables; here's my code:

var ti_arr:Array = new Array;
_global.a = new Object;

for (var t=0; t<group_count-1; t++) {
    numOfItems = group_nodes[t].childNodes.length;
    ti_arr = "tab_info" add t;
    // <-- I want to define a global array with the name held in ti_arr here

    for (var i=0; i<numOfItems; i++) {   
        eval(ti_arr)[i].a.name = tempNode.attributes.name; //<-- or give the array global scope here
        eval(ti_arr)[i].a.value = tempNode.attributes.value;
    }
}

I need: tab_info1.a.name to have global scope.


I've been out of the actionscript loop for a while: eval is bad.. brackets are good.

http://www.kirupa.com/forum/showthread.php?t=259717

It's explained simply here, not sure why so much searching on eval() didn't net me this sooner.

for (var i=0;i<3;i++) {
    ti_arr = "new_array";

    _global[ti_arr] = new Array
    _global[ti_arr][i] = new Object

    _global[ti_arr][i].name = tempnode.name
}
0

精彩评论

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