class Calculator {
constructor(value) {
this.value = value;
}
add(num) {
this.value += num;
return this;
}
getValue = () => this.value;
}
const calc = new Calculator(10);
const addMethod = calc.add;
const getValueMethod = calc.getValue;
addMethod.call({value: 5}, 3);
console.log(calc.getValue());
console.log(getValueMethod());
Ответ: 10 10
JavaScript test | #JavaScript & Max