【发布时间】:2014-06-19 22:56:08
【问题描述】:
我知道我可以通过组合名称来访问用户定义变量的值
window["myvariable"+1234]
我不知道如何访问内部属性的值。我想要类似以下代码的东西,但这有效:
//Suppose there is an object with user-generated property names like myCars.Ford.Focus.mileage and I need a function that reports the value of a certain property only when the content is not an empty string. So we create a function like
function squealProperty(maker,model,UDProp){
if(window["myCars."+maker+"."+model+"."+UDProp+".length"] > 0){
alert("User defined property inspector ("+UDProp+")="+window["myCars."+maker+"."+model+"."+UDProp]);
};
};
在这样的时刻,我通常会在“书”[1] 中找到我祈祷的答案,但这次没有运气。所以我在这里问。 [1] “本书”是指“JavaScript:权威指南”,第 5 版。大卫·弗拉纳根
【问题讨论】:
-
MyCars[maker][model][UDProp].length
标签: javascript object window