Created
November 3, 2023 18:07
-
-
Save xnuk/bc4e9a568ae19943419fa163b1a29f88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const isObject = t => { | |
const z = typeof t | |
return t != null && (z === 'object' || z === 'function') | |
} | |
const traceProxy = (target, name = 'object', recursive = false) => new Proxy(target, { | |
get: (target, prop, receiver) => { | |
const res = Reflect.get(target, prop, receiver) | |
console.log('get prop:', name, prop, '==', res) | |
return recursive && isObject(res) ? traceProxy(res, `${name}[${JSON.stringify(prop)}]`, true) : res | |
}, | |
apply: (target, that, args) => { | |
const res = Reflect.apply(target, that, args) | |
console.log('apply:', that, args, '==', res) | |
return recursive && isObject(res) ? traceProxy(res, `${name}(...${args.length} args)`, true) : res | |
} | |
}) | |
return traceProxy | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment