1.对象属性的增强写法
//ES5写法
const name = "yuan";
const age = "21";
const sex = "man";
const obj = {
name: name,
age: age,
sex: sex
}
//ES6写
const name = "yuan";
const age = "21";
const sex = "man";
const obj = {
name,
age,
sex
}
2.对象方法的增强写法
//ES5写法
const name = "yuan";
const obj = {
getName: function(){
console.log("my name is " + name);
}
}
//ES6写法
const name = "yuan";
const obj = {
getName(){
console.log("my name is " + name);
}
}