1.对象的简写
let value = 12;
//以前的对象赋值
let obj = {
value: value,
method: function () {
return "Hello!";
}
}
// 现在
let obj1 = {
value, //属性简写
method() { //方法的简写
return "Hello!";
}
}
2.属性名表达式
let name = 'ca'
let obj = {};
obj.foo = true;
obj['a' + 'bc'] = 123;
obj['a' + name] = 'dyName';
3.方法的name属性
const person = {
sayName() {
console.log('hello!');
},
};
person.sayName.name // "sayName"