I need to construct a function, which takes a black-box one-argument function as an argument. And I need to know, how many times the black-box function uses its argument
Example signature:
function argCounter(fn) {
return (arg) => {
let argCalls = 0
...
fn(arg)
return argCalls
}
}
Example use:
const fn1 = argCounter(obj => {
return obj
}
fn1() // 1
const fn2 = argCounter(obj => {
obj; obj; obj;
return obj
}
fn2() // 4
I know about JS Proxy, but it only gives me the ability to count how many times an object’s methods or attributes have been called. Unfortunately, I couldn’t determine, how to use JS Proxy to count, how many times the object itself has been used.