Skip to content

Instantly share code, notes, and snippets.

@joshnuss
Created October 9, 2025 16:05
Show Gist options
  • Select an option

  • Save joshnuss/c2679744eb08be69b99701e12d111e95 to your computer and use it in GitHub Desktop.

Select an option

Save joshnuss/c2679744eb08be69b99701e12d111e95 to your computer and use it in GitHub Desktop.
An example of a proxy function
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