4 ms·
Sure. I mean if you have an async function that returns another function (so it actually returns a promise of a function because it's async) proxy of the origin
by kozhevnikov 8y ago
Sure. I mean if you have an async function that returns another function (so it actually returns a promise of a function because it's async) proxy of the original function will call apply handler when invoked, but proxy of the return value will not because it's actually not a function but an object (a promise of a function) and as it turned out proxied objects do not call apply handler when invoked (even if it's defined) but throw an exception.
const handler = { apply: () => { console.log('ok') } };
const foo = new Proxy(() => {}, handler);
const bar = new Proxy({}, handler);
> foo()
< ok
> bar()
< VM313:1 Uncaught TypeError: bar is not a function
at <anonymous>:1:1