属性值的简写
let name ='123'
let person={
name:name
}
let person={
name
}
function renderName(name) {
return {
name
};
}
let person = renderName("huang");
console.log(person.name);//'huang'
可计算属性(可修改属性)
let nameKey = "name";
let ageKey = "age";
let person = {};
nameKey = "NAME";
person[nameKey] = "huang";
person[ageKey] = 23;
console.log(person);//NAME: "huang"
//age: 23
简写方法名
let person = {
sayName: function (name) {
console.log(name);
},
};
let person = {
sayName(name) {
console.log(name);
},
};
网友评论