class Animal {
privateAttribute
setPrivateAttribute(value) {
this.privateAttribute = value
}
}
new Animal().setPrivateAttribute('good way') //ok
new Animal().privateAttribute = 'not allowed' // no
I want to prevent update privateAttribute
directly, the only way to set privateAttribute
is call setPrivateAttribute
function. What shold I do?