class MyCalculator{ constructor(value){ this.value = value } //加 add(data){ this.value = this.value + data return this } //减 minus(data){ this.value = this.value - data return this } //乘 multi(data){ this.value = this.value * data return this } //除 div(data){ this.value = this.value / data return this } //除 pow(data){ this.value = this.value ** data return this } } const calculator = new MyCalculator(123) calculator.add(1).minus(2).multi(3).div(4).pow(2) console.log(calculator.value)