开发者

Name litteral object with parent name

开发者 https://www.devze.com 2023-02-23 06:36 出处:网络
I\'m working with the Google Chrome API and I\'d like to name a litteral object with the parent\'s nameof a node (var tree[0].parentName = {};)

I'm working with the Google Chrome API and I'd like to name a litteral object with the parent's name of a node (var tree[0].parentName = {};)

I'm currently 开发者_JAVA百科searching for the good syntax but if anyone knows -- can they give it to me please?

Thanks,

Bruno


You would need to use eval(); in this case.

Something like this should do the trick (implying the parentName is "aParent") :

eval('var ' + tree[0].parentName + ' = {};');
//A new variable named tree[0].parentName ("aParent" in this example) was created
alert(aParent);

Hope this helps!

0

精彩评论

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