-
-
Save xiongchengqing/a43e9f5ac608808381bd556790aada7f to your computer and use it in GitHub Desktop.
Log all proxy traps
This file contains hidden or 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
function createLoggedProxy(obj) { | |
var traps = {}; | |
for (let trap of Object.getOwnPropertyNames(Reflect)) { | |
traps[trap] = (...args) => { | |
console.log(trap, ...args.slice(0, -1)); // Last arg is always the proxy, no need to log it | |
return Reflect[trap](...args); | |
} | |
} | |
return new Proxy(obj, traps); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment