@nevware21/ts-utils
    Preparing search index...

    Function createProxyFuncs

    • Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.

      Type Parameters

      • T
      • H

      Parameters

      • target: T

        The target object to be assigned with the source properties and functions

      • host: H | (() => H)

        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.

      • funcDefs: ProxyFunctionDef<T, H>[]

        An array of function definitions on how each named function will be proxied onto the target.

      Returns T

      The original target after all proxies have been assigned

      0.9.8

      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