开发者

Name litteral object with parent name

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜