function compute(x) {
return {
add: (y) => {
return compute(Number(x) + Number(y));
},
subtract: (y) => {
return compute(Number(x) - Number(y));
},
multiply:(y) => {
return compute(Number(x) * Number(y));
},
divide: (y) => {
return compute(Number(x) / Number(y));
},
result:() => x
}
}
// use
console.log(compute("10.92").add(10).subtract(10).multiply('10').divide(2).result())
注意: 如果除数是0 结果会是 Infinity