我正在使用一种转换表构建一个与画布相关的类。用户可以编辑转换表。(不是很相关,但也许你想知道为什么):
cLayout = function(option) {
//obtaining the canvas (el) here
this.setup = function(option) {
t=this.table;
for (var p in t)
{
el[t[p][0]] = option[p]||t[p][1]
}
}
this.setup(option)
}
cLayout.prototype.table = {
width:[['style']['width'],"100%"],
height:['style'['height'],"100%"],
bg:[['style']['backgroundColor'],""],
position:[['style']['position'],"absolute"],
left:['style'['left'],"0px"],
top:['style'['left'],"0px"]
}
例子:
var b = new cLayout({left:'10%',width:'90%'})
真正的问题:
通常,我会使用el['style']['width']
设置 el.style.width。但我想不使用el[something]
第二对括号:我希望属性名称是完全可变的(我也希望能够设置el['innerHTML']
)。a[b]
那么,有没有办法通过使用而不使用来获得孙子a[b][c]
?
PS当然,我不想用eval。