Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created February 8, 2022 01:04
Show Gist options
  • Save DavidWells/5418a4920d1e35b2c58441b3ea2289ba to your computer and use it in GitHub Desktop.
Save DavidWells/5418a4920d1e35b2c58441b3ea2289ba to your computer and use it in GitHub Desktop.
Alter function args via JS proxy
// via https://blog.sessionstack.com/how-javascript-works-proxy-and-reflect-11748452c695
const p = new Proxy(function() {}, {
apply: function(target, thisArg, argumentsList) {
console.log('called: ' + argumentsList.join(', '));
return argumentsList[0] + argumentsList[1] + argumentsList[2];
}
});
console.log(p(1, 2, 3)); // This will print called: 1, 2, 3 and 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment