Created
February 8, 2022 01:04
-
-
Save DavidWells/5418a4920d1e35b2c58441b3ea2289ba to your computer and use it in GitHub Desktop.
Alter function args via JS proxy
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
// 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