Skip to content

Instantly share code, notes, and snippets.

@xiongchengqing
Forked from LeaVerou/log-traps.js
Created August 11, 2017 02:51
Show Gist options
  • Save xiongchengqing/a43e9f5ac608808381bd556790aada7f to your computer and use it in GitHub Desktop.
Save xiongchengqing/a43e9f5ac608808381bd556790aada7f 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