@s-libs/js-core
    Preparing search index...

    Function wrapMethod

    • Replaces a method on object with a wrapped version that will call the provided hooks in addition to the original method. See wrapFunction() for more details on the hooks.

      Type Parameters

      • K extends string | number | symbol
      • O extends Record<K, (...args: any) => any>

      Parameters

      • object: O
      • key: K
      • hooks: Hooks<Parameters<O[K]>, ReturnType<O[K]>, ThisType<O[K]>>

      Returns () => void

      a function to reset the method to its previous, unwrapped state

      // log all get requests to the console
      wrapMethod(HttpClient.prototype, "get", {
      before(url) {
      console.log("Sending GET request to", url);
      }
      });

      // suppress benign error messages
      const unwrap = wrapMethod(console, "error", {
      around(original, ...args) {
      if (args[0].message !== 'something benign') {
      original(...args);
      }
      }
      });

      // remove error suppression (from above)
      unwrap();