类 / 方法

class Counter {
    constructor() {
        this.count = 0;
    }

    incBy(value) {
        this.count += value;
    }

    incByAmount(value, amount) {
        this.count += value * amount;
    }
}

let counter = new Counter();
counter.incBy(1);
//counter.count is 1
console.log("count is", counter.count);

counter.incByAmount(25);
//counter.count is 11
console.log("count is", counter.count);