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

 

posted @ 2020-05-11 22:27  莫欺少年穷呐  阅读(721)  评论(0编辑  收藏  举报