class Hero extends Character {
constructor (name, race, gender, role, level){
super(name, race, gender, role, level);
this.inventory = [];
this.experience = {
experienceNeeded: 100,
experienceObtained: 0
};
this.gold = 0;
}
I have this class which defines how a player Character will be. I want to make both experienceObtained
and gold
properties unchangeable through reassignment but modifiable through operators to avoid users set their own values to these properties using console.
this.gold = {
amount: 0,
get gold(){
return this.amount;
}
};
As showed above I tried using a getter without declaring a setter but I still can assign amount
any value through console.
I don't know if I am misunderstanding the use of getters and setters in JavaScript or if it is not possible to do.