0
have this following class javascript:
class Usuario {
constructor() {
this._nome = '';
this._idade = '';
}
get nome() {
return this._nome;
}
set nome( value ) {
this._nome = value;
}
get idade() {
return this._idade;
}
set idade( value ) {
this._idade = value;
}
}
When I return she saw json
, she returns me the names with _
at first. I know this sign means that the attribute can only be used within the class itself, so I’d like to return the attribute names without this character.
How about taking the
_
that it’s just noise in the name?– Maniero
But good practice says it’s good to encapsulate the data.
– Rafael Silva
This is completely absurd. Read some of these answers: https://answall.com/search?q=user%3A101+boas+pr%C3%A1ticas I have a talk about the harm people are doing to others and themselves with this good practice business.
– Maniero
You may be right, but the question isn’t about good practice.
– Rafael Silva
Who argued about good practice was you, I just replicated what you said. I gave you an easier and more correct solution, I would do the right thing, but it’s your right not to do it.
– Maniero