我有一个这样类型的复杂对象:
class Person {
constructor(name, age, country) {
this.name = name;
this.age = age;
this.country = country;
}
setName(name) {
if (name !== null) this.name = name;
}
setAge(age) {
if (age !== null) this.age = age;
}
setCountry(country) {
if (country !== null) this.country = country;
}
getName() {
return this.name;
}
// ...
}
let person = new Person('Paul', 27, 'Haïti'); // needs to save this Object
console.log(person);
我想知道有没有什么办法可以把这个对象存储起来,以便下次打开浏览器时可以访问它。localStorage不能使用。