为什么此代码的工作...在JavaScript中不能定义变量对象字面
var message = {
texts: {
text1: 'Hello',
text2: 'World'
},
greet: function() {
console.log(this.texts.text1 + ' ' + this.texts.text2 + '!');
}
}
message.greet();
...但是这不?
var message = {
texts: {
text1: 'Hello',
text2: 'World'
},
both: this.texts.text1 + ' ' + this.texts.text2 + '!',
greet: function() {
console.log(this.both);
}
}
message.greet();
它给我“两个都没有定义”的错误。我在这里错过了什么? this.both
有什么不对吗?我是新手,当谈到对象文字
'类型错误:的undefined' –
无法读取属性“文本1”难道只是我还是应该两个例子不行 – aaronman