Почему свойство функции не записывается?
function work(a, b) {
console.log(a + b);
}
function spy(func) {
func.calls = [];
function f(...args) {
func.calls.push(args);
return func(...args);
}
return func;
}
work = spy(work);
work(2, 6);
Ответы (1 шт):
Автор решения: Igor
→ Ссылка
function work(a, b) {
console.log(a + b);
}
function spy (func) {
f.calls = [];
function f(...args){
f.calls.push(args);
return func(...args);
}
return f;
}
work = spy(work);
work(2, 6);
work(3, 4);
console.log(work.calls);