The problem
I'd like to be able to use classes to create client objects and add address objects to an array within them.
What I'd like to be able to do
let client = new Client ('A123', 'John', 'Smith', avatarUrl);
client.address('home').add(address);
My current classes
Working version
class Client extends Name {
constructor(clientRef, firstName, lastName, profilePic) {
super (firstName, lastName, profilePic);
this._id = clientRef;
this.addresses = [];
}
addAddress (address, label = 'main') {
address = {...address, label}
this.addresses.push(address);
}
removeAddress (label = 'main') {
this.addresses = this.addresses.filter((element) => { return element.label != label; });
}
}
Non-working version
This is what I'm trying to create, but it doesn't work.
class Client extends Name {
constructor(clientRef, firstName, lastName, profilePic) {
super (firstName, lastName, profilePic);
this._id = clientRef;
this.addresses = [];
}
address (label = 'main') {
add (address) {
address = {...address, label}
this.addresses.push(address);
}
remove () {
this.addresses = this.addresses.filter((element) => { return element.label != label; });
}
}
}