class Add { constructor() { this.num = 0; } add(val) { return this.num += val; } } const numAdd = new Add(); numAdd.add(1); // 1 numAdd.add(1); // 2
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