Сообщение от Nexus
|
worldsering,
class Counter {
constructor(initialValue = 1) {
this.value = initialValue;
}
multiply(value) {
return this.value *= value;
}
}
var counter = (
counter => counter.multiply.bind(counter)
)(new Counter(1));
console.log([
counter(5) === 5,
counter(2) === 10,
counter(3) === 30,
counter(2) === 60,
]);
|
Сообщение от Vlasenko Fedor
|
function math(value) {
if (this.store === undefined) {
this.store = value
} else {
this.store *= value
}
return this.store
}
console.log(math(5)) // 5
console.log(math(2)) // 10
console.log(math(3)) // 30
функция это объект
внутри объекта можно хранить значения
|
____________________________________________
Спасибо, но это не работает так, как мне нужно ...
const number5 = math(5);
const number10 =
number5(2); // и уже тут мне пишет, что number5 не функция
const number30 = number10(3);
number30(2) \\ уже естественно ничего не выдаст