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!
精彩评论