Created
October 9, 2025 16:05
-
-
Save joshnuss/c2679744eb08be69b99701e12d111e95 to your computer and use it in GitHub Desktop.
An example of a proxy function
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
| function add(a: number, b: number) { | |
| return a + b | |
| } | |
| function multiply(a: number, b: number) { | |
| return a * b | |
| } | |
| function doubler<T extends Function>(fn: T): T { | |
| return new Proxy(fn, { | |
| apply(target, self, args) { | |
| return Reflect.apply(target, self, args) * 2 | |
| } | |
| }) | |
| } | |
| const double_add = doubler(add) | |
| const double_multiply = doubler(multiply) | |
| console.log(double_add(1, 3)) | |
| console.log(double_multiply(2, 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment