<分区>
我想在一个步骤中计算 full
属性作为 first
和 last
属性的结果,如下所示:
const name = {
first: 'John',
last: 'Doe',
full: `${this.first} ${this.last}`, // undefined
}
但是 name.full
是 undefined
。
我做错了什么?
标签 javascript
<分区>
我想在一个步骤中计算 full
属性作为 first
和 last
属性的结果,如下所示:
const name = {
first: 'John',
last: 'Doe',
full: `${this.first} ${this.last}`, // undefined
}
但是 name.full
是 undefined
。
我做错了什么?
最佳答案
const name = {
first: 'John',
last: 'Doe',
get full() {
return `${this.first} ${this.last}`;
}
}
console.log(name.full);
关于javascript - 如何在创建 JS 对象文字期间根据其他属性值 "inline"计算属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57912974/
相关文章:
javascript - Knockout.JS:从模型到 View 的不同值
javascript - ES6 : How to Import and Export modules and keep access from console
javascript - IconMenu 没有出现在 material-ui 中
php - 如何使用javascript获取浏览器存储的cookie
javascript - 如何告诉 Razor 不要 html 转义
javascript - 为什么 `$(document) === $(document)` 在 jQuery 中返回 false?