对象内部引用声明 [英] Object internal reference declarations

查看:97
本文介绍了对象内部引用声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在注意使用字典中的值作为字典内部引用的快捷方式。代码显示了我的意思:

I'm watching out for a shortcut way to use values from a dictionary as an internal reference inside the dictionary. The code shows what I mean:

var dict = {
    'entrance':{
        'rate1': 5,
        'rate2':10,
        'rate3':20,
    },

    'movies':{
        'theDarkKnight':{
            '00:00':<entrance.rate1>,
            '18:00':<entrance.rate2>,
            '21:00':<entrance.rate3>
        },
        ...
    };

有一种偷偷摸摸的方法吗?

is there a sneaky way to do this?

推荐答案

不。你能做的最好的是:

No. The best you can do is:

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
    },
    ...
};

这篇关于对象内部引用声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆