如何在声明时从同一JSON获取另一个对象的值?
var constant = {
roles: {
ADMIN: 'admin',
CONSUMER: 'consumer',
SUPER_ADMIN: "super_admin"
},
webAccess : [roles.ADMIN]
}
console.log(constant);
预期输出:
{
"roles": {
"ADMIN": "admin",
"CONSUMER": "consumer",
"SUPER_ADMIN": "super_admin"
},
"webAccess": [
"admin"
]
}
答案 0 :(得分:0)
您可以执行以下操作:
var constant = {
roles: {
ADMIN: 'admin',
CONSUMER: 'consumer',
SUPER_ADMIN: "super_admin"
},
get webAccess() {
return [this.roles.ADMIN];
}
}
console.log(constant);