Created
May 20, 2024 16:52
-
-
Save helabenkhalfallah/b77267a473c45404684ef10bc85b2f0b to your computer and use it in GitHub Desktop.
Proxy Apply Example
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
const target = function(a, b) { | |
return a + b; | |
}; | |
const handler = { | |
apply: function(target, thisArg, argumentsList) { | |
console.log(`Called with arguments: ${argumentsList}`); | |
return target.apply(thisArg, argumentsList); | |
} | |
}; | |
const proxy = new Proxy(target, handler); | |
console.log(proxy(1, 2)); // Logs: Called with arguments: 1,2. Output: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment