I want to save or store the outcome of a property in a class to use in another property in the same class. How do I do that?
for example:
class MyClass {
get randomNumber() {
let number = Math.floor(Math.random() * 10) + 1
return number
}
get newSum() {
return this.randomNumber + 1 // I want to use the result from the previous property and add 1 to that
}
}
```
Aucun commentaire:
Enregistrer un commentaire