使用动态创建的变量来访问对象中的命名对象

时间:2015-03-26 23:27:09

标签: javascript

finalVariables()返回一个对象,该对象包含.dataName表示法可访问的数据,即finalVariables()。mainViewWindow0返回为mainViewWindow0存储的字符串。我正在尝试使用动态创建的变量访问mainViewWindow0,但由于显而易见的原因,使用点表示法不能很好地工作,但我不知道如何解决它。帮帮我吧?

请忽略在那里使用硬编码号码的不良编码做法;我保证稍后会摆脱它

activePane = dot.id.substring(6); //gets dot # and sets it as active pane 
	var tempForPaneNumber = "mainViewWindow" + activePane + "";
	document.getElementById("mainViewWindowContent").innerHTML = finalVariables().@@@this is where I want to use 
        the string from "tempForPaneNumber" to access @@@

2 个答案:

答案 0 :(得分:1)

finalVariables[tempForPainNumber]()

如果我理解正确,应该采取行动。

答案 1 :(得分:1)

在Javascript中,您可以通过点表示法或通过使用括号来访问对象的属性,以指定属性的标识符,因此myVar.foo等同于myVar['foo']。因此,如果我理解您的要求,请使用finalVariables()[tempForPaneNumber]()