Learn JavaScript Syntax: Objects | Codecademy
In the exercise Team Stats is asked to create a propertie called _players and then a getter for players that returns the _players value.
get players() {
return this._players
},
In the next steps is also asked to create a method addPlayer that takes the parameters of the new player and push into the getter players.
addPlayer(firstName, lastName, age) {
let player = {
firstName: firstName,
lastName: lastName,
age: age
};
this.players.push(player);
},
My question is, why push for getter players instead to _players property?
this._players.push(player);
This way, at the end of the excersise I can also log the _players property instead the getter:
console.log(team._players);
Removing the getter I can make the code cleaner, can’t I?