Hi all,
it was mentioned on JS course that we use getters to access a property and setter to mutate a property.
How can I create a person object as below, and use getter to have read-only property on the firstName and a setter to be able to mutate the lastName?
Apparently I am able to create this object and being able to have access to ready-only using get, but how can I implement a setter?
const person = {
get firstName() {
return 'John';
},
set firstName(value) { //this part gives me a range error;
return this.firstName = value;
},
lastName: 'Smith',
}
person.firstName = 'David'
console.log(person.firstName)