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 };
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: es6中export default的含义是什么