我正在寻找一种使用字典中的值作为字典内部引用的快捷方式。代码显示了我的意思:
var dict = {
'entrance':{
'rate1': 5,
'rate2':10,
'rate3':20,
},
'movies':{
'theDarkKnight':{
'00:00':<entrance.rate1>,
'18:00':<entrance.rate2>,
'21:00':<entrance.rate3>
},
...
};
有什么偷偷摸摸的方法吗?
最佳答案
没有。你能做的最好的事情是:
var dict = {
'entrance' : {
'rate1' : 5,
'rate2' : 10,
'rate3' : 20,
}
};
dict.movies = {
'theDarkKnight' : {
'00:00' : dict.entrance.rate1,
'18:00' : dict.entrance.rate2,
'21:00' : dict.entrance.rate3
},
...
};
关于javascript - 对象内部引用声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13686161/