Почему значение функции не сохраняется?
fire = () => {
console.log('fire');
}
const once = function(fn) {
var show = true;
return function() {
if (show) {
fn();
show = false;
}
}
}
const f = once(fire)
const result = f()
f()
f()
f()
f()
console.log(result);
// вывод Fire
// undefined
Ответы (1 шт):
Автор решения: Igor
→ Ссылка
fire = () => {
console.log('fire');
return 'fire';
}
const once = function(fn) {
var show = true;
return function() {
if (show) {
show = false;
return fn();
}
}
}
const f = once(fire)
const result = f()
f()
f()
f()
f()
console.log(result);