【发布时间】:2018-07-29 07:04:55
【问题描述】:
const Color = {
RED: 'red',
GREEN: 'green',
BLUE: 'blue',
values: [this.RED, this.GREEN, this.BLUE],
allValues() {
return [this.RED, this.GREEN, this.BLUE]
}
}
console.log(Color.values); // [undefined, undefined, undefined]
console.log(Color.allValues()); // ["red", "green", "blue"]
我最近开始学习 javascript,这让我很吃惊,我会考虑通过将其包装在一个 hacky 函数中来使其工作,并且真的很想避免这样做。我在这里做错了什么?
【问题讨论】:
-
"使用对象字面量语法时,初始化时不能引用对象,对象创建后需要引用。"请参阅上面的链接。
标签: javascript node.js