An object doesn't have the keyword
this. A
method has the keyword
this. Semantically speaking, there is no way to define a method outside of a class definition. You would need to define a function with the
this parameter explicitly, at the start of the parameter list, and then use that function as a method.
Each method has a hidden parameter named this, which typically contains a reference to an object derived from the class. However, it could contain a reference to the class itself or a derived class, depending on how the method was called. Methods are stored by reference in the class object.
Source: Objects
class A {
M() {
MsgBox % "M called via " this.__Class
}
}
B := {}
B.M := A.M
B.__Class := "B"
C := {}
C.M := Func("C_M")
C.__Class := "C"
C_M(this) {
MsgBox % "M called via " this.__Class
}
_a := new A
_a.M()
_b := new B
_b.M()
_c := new C
_c.M()
Note: This is covered under
Objects - Prototypes.
Or a function that can save/load a class to/from A File.
AutoHotkey_L doesn't support that.
AutoHotkey.dll might.