class Creature {
secretProperty
modifySecretProperty(value) {
this.secretProperty = value
}
}
new Creature().modifySecretProperty('hidden way') //success
new Creature().secretProperty = 'not permitted' // failure
To restrict direct updates to secretProperty
, the only method should be calling modifySecretProperty
function. How can I achieve this?