SOURCE

// 请实现一个模块 math,支持链式调用 math.add(2,4).minus(3).times(2);
let math = {
    cur: 0,
    add:function (a, b){
        this.cur += a+b
        return this
    },
    minus:function (a){
        this.cur -= a
        return this
    },
    times:function (a){
        this.cur *= a
        return this
    },
    getRes(){
        return this.cur
    }
}

console.log(math.add(2,4).minus(3).times(2).getRes())
console 命令行工具 X clear

                    
>
console