Skip to content

Instantly share code, notes, and snippets.

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