[2.0-rc1] Bug Report (Maybe)?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
aliztori
Posts: 117
Joined: 19 Jul 2022, 12:44

[2.0-rc1] Bug Report (Maybe)?

Post by aliztori » 04 Dec 2022, 12:11

hello
i have a class inside another class(Subclass)
but i cant access toBaseClass in Sub Class With Super
https://lexikos.github.io/v2/docs/Objects.htm#Custom_Classes_super
you can make a simple code and

Code: Select all

class MyClass {

    static myproperty {
        get {
            Return true
        }
    }

    static mymethod() {
        Msgbox("This msgbox never display!")
    }
    
    Class MySubclass {

        static MethodinSubClass() {
            super.mymethod()
       }
    }

}

MyClass.MySubClass.MethodinSubClass()

here example

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [2.0-rc1] Bug Report (Maybe)?

Post by Helgef » 04 Dec 2022, 13:11

A nested class is not what is meant by subclass. A subclass is a class which extends/inherits from another class, which is its super class,

Code: Select all

class mySubclass extends mySuperclass{
	static a()=>super.b()
}
class mySuperclass{
	static b()=>msgbox()
}
mySubclass.a
Cheers

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [2.0-rc1] Bug Report (Maybe)?

Post by swagfag » 04 Dec 2022, 13:16

aliztori wrote:
04 Dec 2022, 12:11
i have a class inside another class(Subclass)
no, what u have is a "class inside another class(Nested class)". it has no relationship to its enclosing outer class, other than the mere fact that its being enclosed by it
u can cut off bits from the class name and try retrieving a reference to the outer class dynamically(or u could have ensured a reference was provided explicitly to begin with)

Code: Select all

class MyClass {
    static myproperty => true
    static mymethod() => Msgbox("This msgbox never display!")

    Class MySubclass {
        static MethodinSubClass() => %RegExReplace(this.Prototype.__Class, '.*\K\..*')%.mymethod()
    }
}

MyClass.MySubClass.MethodinSubClass()

aliztori
Posts: 117
Joined: 19 Jul 2022, 12:44

Re: [2.0-rc1] Bug Report (Maybe)?

Post by aliztori » 04 Dec 2022, 14:41

Helgef wrote:
04 Dec 2022, 13:11
A nested class is not what is meant by subclass. A subclass is a class which extends/inherits from another class, which is its super class,

Code: Select all

class mySubclass extends mySuperclass{
	static a()=>super.b()
}
class mySuperclass{
	static b()=>msgbox()
}
mySubclass.a
Cheers
oh my bad i mean nested class
btw i cant use function that in myclass(MainClass) in my nested class

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [2.0-rc1] Bug Report (Maybe)?

Post by Helgef » 09 Dec 2022, 13:22

i cant use function that in myclass(MainClass) in my nested class
No you can't, by using super. Alternatively you can create a property through which you can reference the enclosing class, if you do not mind the circular reference,

Code: Select all

class MyClass {
	static __new()=>this.MySubclass.outer := this
	; Or
	static __new() {
		for name, value in this.ownprops()
			if value is Class
				value.outer := this
	}
	
    static myproperty => true
    static mymethod() => Msgbox("This msgbox never display!")

    Class MySubclass {
        static MethodinSubClass() => this.outer.mymethod()
    }
}
MyClass.MySubClass.MethodinSubClass()
Cheers

Post Reply

Return to “Ask for Help (v2)”