AHK V2: function reference works to class prototype method but not class instance method
Posted: 18 Jul 2018, 19:14
I've been trying to dig out of the object/class rabbit hole for weeks now.
Current mystery: the following test has me pondering what I'm missing. Not that I'm looking to code like this, but am wondering why I can create a function reference to a class prototype method, but not to the class instance method that appears to be the exact same func object?
Current mystery: the following test has me pondering what I'm missing. Not that I'm looking to code like this, but am wondering why I can create a function reference to a class prototype method, but not to the class instance method that appears to be the exact same func object?
Code: Select all
; To extend a GeekDude example:
MyFunction(this, Param1, Param2)
{
MsgBox Param1 " has " this.Apples " apples for " Param2 " customers"
}
class MyClassPrototype
{
Apples := 5
MyMethod(Param1, Param2)
{
MsgBox Param1 " has " this.Apples " apples for " Param2 " customers"
}
}
MyClass := new MyClassPrototype
MyClass.MyMethod("Johnny", 123)
MyClassPrototype_MyMethod_Addr := &MyClassPrototype.MyMethod
MyClass_MyMethod_Addr := &MyClass.MyMethod ; same address
MyClass_MyMethod_Addr := &MyClass.base.MyMethod ; same address
MyObj := {
;MyMethod: Func("MyFunction"), ; standard function reference
; (works fine)
MyMethod: Func("MyClassPrototype.MyMethod"), ; works for class prototype,
; but not for class instance:
;MyMethod: Func("MyClass.MyMethod"), ; doesn't work = empty
;MyMethod: Func("MyClass.base.MyMethod"), ; doesn't work = empty
MyClassApples: MyClass.Apples, ; 5
Apples: 4
}
MyObj.MyMethod("Johnny", 123)