javascript get trace from function code example
Example: js trace function call
function traceMethodCalls(obj) {
const handler = {
get(target, propKey, receiver) {
const targetValue = Reflect.get(target, propKey, receiver);
if (typeof targetValue === 'function') {
return function (...args) {
console.log('CALL', propKey, args);
return targetValue.apply(this, args);
}
} else {
return targetValue;
}
}
};
return new Proxy(obj, handler);
}
const objWithFunction = {
methodA: (a) => { return a; }
}
const proxyWithTrace = traceMethodCalls(objWithFunction);