The target object to be assigned with the source properties and functions
The host instance or a function to return the host instance which contains the
functions and will be assigned as the this
for the function being called.
An array of function definitions on how each named function will be proxied onto the target.
The original target after all proxies have been assigned
let test = {
x: 21,
func1() {
return this.x;
}
};
test.func1(); // 21
let newTarget = createProxyFuncs({} as any, test, [
{ n: "func1" },
{ n: "func1", as: "aliasFn" }
]);
newTarget.func1(); // 21
newTarget.aliasFn(); // 21
newTarget.x = 42;
// The return is still using the `this.x` from the original `test` as it's proxied
newTarget.func1(); // 21
newTarget.aliasFn(); // 21
let getHostFn = () => {
return test;
};
newTarget = createProxyFuncs({} as any, getHostFn, [
{ n: "func1" },
{ n: "func1", as: "aliasFn" }
]);
newTarget.func1(); // 21
newTarget.aliasFn(); // 21
newTarget.x = 42;
// The return is still using the `this.x` from the original `test` as it's proxied
newTarget.func1(); // 21
newTarget.aliasFn(); // 21
Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.