js 面向对象实现累加

class Add {
    constructor() {
        this.num = 0;
    }
    add(val) {
        return this.num += val;
    }
}
const numAdd = new Add();
numAdd.add(1);  // 1
numAdd.add(1);  // 2
愿世间所有的美好都会降临到每个人的身边
原文地址:https://www.cnblogs.com/boystao/p/12872698.html