Jump to content

How to override TJS2 classes with the same name


Recommended Posts

It is possible to override a TJS2 class with the same name, but you must follow the following rules:

1. Use a unique identifier when declaring a class

Example of this wrong usage:

global.ClassToOverride_original = global.ClassToOverride;
class ClassToOverride extends global.ClassToOverride_original
{
}
	

When instantiating the class, this will cause a segmentation fault.

2. Do not use an identifier that has been deleted

Example of this wrong usage:

global.ClassToOverride_original = global.ClassToOverride;
delete global.ClassToOverride;
class ClassToOverride extends global.ClassToOverride_original
{
}
	

This will cause Member does not exist exception.

3. Place the original class name as the constructor

With these three rules, we can override a TJS2 class while keeping the same name.

global.ClassToOverride_uniqueidentifier_original = ClassToOverride;
class ClassToOverride_uniqueidentifier_override extends ClassToOverride_uniqueidentifier_original
{
    function ClassToOverride_uniqueidentifier_override()
    {
        super.ClassToOverride(...);
    }
	 function ClassToOverride()
    {
        ClassToOverride_uniqueidentifier_override(...);
    }
}
global.ClassToOverride = ClassToOverride_uniqueidentifier_override;
	

This is a cleaner way of adding features like word wrapping or line breaking to KAG, compared to some code I've seen.

Edited by uyjulian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...