Answer
t.me/js_testОтвет:
function Accumulator(val) {
this.value = val;
this.read = function (newVal) {
this.value += newVal;
};
}
Обьяснение:
Присваием стартовое значение val в this.value. Создаём метод this.read, который принимает один аргумент и добавляет его к this.value.
Код для проверки:
function Accumulator(val) {
this.value = val;
this.read = function (newVal) {
this.value += newVal;
};
}
let accumulator = new Accumulator(1);
accumulator.read(2);
accumulator.read(5);
console.log(accumulator.value); // 8