Making something serializable
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
let bart = new Person('Bart', 'Simpson');
bart.valueOf() // this is not what we want because this is a complex instance
class PersonOfValue extends Person {
valueOf() {
const { firstName, lastName } = this;
return { firstName, lastName };
}
}
let bartOfDistinction = new PersonOfValue('Bart', 'Simpson');
bartOfDistinction.valueOf(); // this is what we want
no comments