Monkey-patching default classes?

Hi! I need help with something related to coffeescript. In the documentation provided it is suggested not to edit directly the source files. My problem is that I need to add and modify some functions on already existing classes. For instance, I need to edit the function createControl in class Formula inside the UIManager file. How can I do that without actually modifying the class directly? Is there any way to do that on a new script file referencing the original file? Sorry for bothering but I'm new to coffeescript "^^ Thanks in advance for your help!
I'm not sure at all this is going to work but just importing a new script containing a class already defined in another one should do the trick as long as the original class is positioned above yours.
Unfortunately that doesn't seem to work, maybe I'm doing something wrong.
I created a new folder for my scripts, and I moved that just above "main". I created a new coffeescript file and put this in it:

Code:
class UIManager

    createAnimationImage: (descriptor) ->
        control = new ui.Object_Image(descriptor.image, descriptor.imageHandling)                
        if descriptor.imageFolder?
            control.imageFolder = descriptor.imageFolder            
        if descriptor.looping?
            control.visual.dispose()
            control.removeComponent(control.visual)
            control.visual = new gs.Component_TilingSprite()
            control.addComponent(control.visual)            
            control.visual.looping.vertical = descriptor.looping.vertical
            control.visual.looping.horizontal = descriptor.looping.horizontal
        if descriptor.color?
            control.color = Color.fromArray(descriptor.color)                    
        return control

I'm working on a component for animated images, so I'm starting by copying the already existing image component. However, if I try to reference this new function, the screen simply goes black and I see nothing.
If I copy this function in the original "UIManager" class it works fine if I call it, so I'm guessing that I have to alias / extend / monkey patch the code in some way or another, but I have no idea on how to do that here ^^'
In VNM documentation, it is explained how to create with a testbed. "extends" keyword is used to achieve that, I guess (maybe).
Hi, you code is almost correct. You just have to add:

Code:
ui.UiFactory = new UIManager()
ui.UIManager = ui.UiFactory

at the end of your script to overwrite the global UI manager instance with your own one. Let me know if that helps you out.
Hi, you code is almost correct. You just have to add:

Code:
ui.UiFactory = new UIManager()
ui.UIManager = ui.UiFactory

at the end of your script to overwrite the global UI manager instance with your own one. Let me know if that helps you out.
Hello, thanks for the code! Unfortunately if I add those two lines I get a black screen and nothing shows up. If I remove those two lines (and remove every call on my method) the program runs just fine!

Maybe it is because I'm not copying EVERYTHING but only adding one function?

Original thread: https://forums.rpgmakerweb.com/threads/monkey-patching-default-classes.91366/