Last active
January 28, 2018 12:22
-
-
Save LeaVerou/59cf8f2d8c21efb0966fcb9ee545edb5 to your computer and use it in GitHub Desktop.
Log all proxy traps
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
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