对象字面量的扩展
对象属性名,方法名的简写方式
const name = 'laravel';
const age = 2;
const birthday = '2015-09';
const laravel = {
name,
age,
birthday,
greet() {
console.log('Hello!');
}
}
console.log(laravel);
计算属性
let id = 0;
const userIds = {
[`user-${++id}`]: id,
[`user-${++id}`]: id,
}
console.log(userIds);
const keys = ['name', 'age', 'birthday'];
const values = ['Laravel', 2, '2015-09'];
const laravel = {
[keys.shift()]: values.shift(),
[keys.shift()]: values.shift(),
[keys.shift()]: values.shift(),
}
console.log(laravel);