ES6创建对象的方法有以下几种:
const person = { name: 'Alice', age: 20 };
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
const person = new Person('Alice', 20);
const person = Object.create(null);
person.name = 'Alice';
person.age = 20;
const obj1 = { name: 'Alice' };
const obj2 = { age: 20 };
const person = Object.assign({}, obj1, obj2);
const obj1 = { name: 'Alice' };
const obj2 = { age: 20 };
const person = { ...obj1, ...obj2 };