79170121

Date: 2024-11-08 13:05:28
Score: 1.5
Natty:
Report link

I want to intercept function calls and found that proxies can do that

Far too complicated. All you need is a wrapper function:

// Trapping a function call with another function
const taggedTemplate = (...argArray) => {
  console.log("apply");
  return target(...argArray);
};

The proxy doesn't achieve anything else here.

I quickly found that the params passed to the function are not intercepted. Why is that?

Because only taggedTemplate is a proxy (or wrapped function), and the apply trap triggers when that particular taggedTemplate function object is called. There is no proxy involved in Num(). The expression taggedTemplate`my fav number is ${Num()}` is no different than doing

const value = Num();
taggedTemplate`my fav number is ${value}`

Is there any way to do that?

No.

Reasons:
  • Blacklisted phrase (1): Is there any
  • RegEx Blacklisted phrase (1): I want
  • RegEx Blacklisted phrase (0.5): Why is that
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-2):
Posted by: Bergi