console.log(myDog) before and after myDog.eatTooManyTreats() prints two different values, 12 and 13. Can't really understand why that's happening, isn't objects passed by reference, which means they can't have two different states. Thanks for your attention.
const dogFactory = (_name, _breed, _weight) => {
return dogObj = {
_name,
_breed,
_weight,
get name () {
return this._name;
},
get breed () {
return this._breed;
},
get weight () {
return this._weight;
},
set name (value) {
return this._name = value;
},
set breed (value) {
return this._breed = value;
},
set weight (value) {
return this._weight = value;
},
bark() {
return console.log('ruff! ruff!');
},
eatTooManyTreats() {
return this._weight++;
}
}
}
const myDog = dogFactory('Dodo', 'Milk', 12);
console.log(myDog); // weight is 12
myDog.eatTooManyTreats();
console.log(myDog); // weight is 13