只要常量的值等于映射中的键,是否可以使用常量而不是映射中的键?JS/ES6在map.get中引用常量
const myColor = 'dark';
const myMap = new Map();
myMap.set('dark', {
primary: '#000',
});
const myValues: {
first: myMap.get(myColor).primary,
}
^This should output to 'dark' and access the primary key.
好吧,这一定不是我的问题,然后,我得到一个意想不到的标记错误,在myColor的开幕式上。 – stephenway
@Potter - 注意,我在'myValues'声明中添加了关于语法错误的注释。 – jfriend00
啊,是的'='是我失踪的!感谢你的全力帮助。 – stephenway