我想保存或存储类中某个属性的结果,以便在同一类中的另一个属性中使用。我怎么做?
例如:
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
}
}
```
扬帆大鱼
相关分类