MZ (SOLVED) Modify existing function without redefining it?

Howdy
I'm currently making a plugin that adds some QoL and new features to an existing plugin.
I wanted to know, is there any way to modify an existing function from within the parent plugin without having to fully copy and redefine it in my own addon plugin? Probably a stupid simple answer, but I'm stumped.

If a thread relating to this topic already exist I'm sorry I couldn't find anything, at least using the terms I'm describing this as. I'd appreciate a link to it ^^
only by editing the original function instead, and that can have many problems.
From the licence of the plugin (edits allowed or not) over compatibility issues to update issues (you'll have problems updating the plugin after you edited it).

copying and overwriting the original function is the safer solution
You can patch the function so that additional code runs before and/or after it, e.g.
JavaScript:
(() => {
  const alias = Some_Thing.prototype.method;  // store current function
  Some_Thing.prototype.method = function() {  // set equal to new function
    console.log("before");
    alias.apply(this, arguments);  // run stored function
    console.log("after");
  };
})();
Otherwise you need a full override. Like Andar says, remember to check the author's terms of use!
If they hid the custom function within the IIFE encapsulation (which apparently many plugin creators do), you're out of luck. You have to edit the plugin itself.

If you don't know what IIFE is, if you see this structure
Code:
(() => {
   // Code here
})();
like caethryil has posted, it is IIFE.

More discussion about it.
You can patch the function so that additional code runs before and/or after it, e.g.
JavaScript:
(() => {
  const alias = Some_Thing.prototype.method;  // store current function
  Some_Thing.prototype.method = function() {  // set equal to new function
    console.log("before");
    alias.apply(this, arguments);  // run stored function
    console.log("after");
  };
})();
Otherwise you need a full override. Like Andar says, remember to check the author's terms of use!
Thank you so much, works perfectly!

And yes I'm being mindful of terms of use and what not,
just wanted to add some stuff to some of Moghunter's plugins with an addon, and they're cool with modification as well as redistribution as stated here.

Thank you all ^^

Original thread: https://forums.rpgmakerweb.com/threads/solved-modify-existing-function-without-redefining-it.162064/