pidgay wrote:but field of class = key of object in Autohotkey????
Autohotkey uses prototype based inheritance, everything is a key of object or a key of the base(prototype) object or the key of the base of the base object...
This includes constructors, destructors, properties, meta properties...
In Autohotkey "field of class" is just a key that is added in the auto generated
__Init method, this method is called before the constructor(
__New) when you use the
new keyword.
A class in Autohotkey is not really a class but just syntactic sugar for the following:
Code: Select all
protoTest := {}
protoTest.__Class := "protoTest"
protoTest.__Init := Func("protoTest__Init")
protoTest.__New := Func("protoTest__New")
protoTest.print := Func("protoTest_print")
protoTest__Init(this) {
this.var1 := 1
}
protoTest__New(this) {
this.var2 := 2
}
protoTest_print(this) {
MsgBox % "var1:" this.var1 " var2:" this.var2 " class:" this.base.__Class
}
; protoTest is now a "class" and we can create new instances of it
t := new protoTest
t.print()
The above code is exactly the same as:
Code: Select all
class Test {
var1 := 1
__New() {
this.var2 := 2
}
print() {
MsgBox % "var1:" this.var1 " var2:" this.var2 " class:" this.base.__Class
}
}
t := new Test
t.print()
If you are coming from languages with "real" classes that use class based inheritance like Java, c# or c++ this might seem strange but you will get used to it.
You should thoroughly read
https://autohotkey.com/docs/Objects.htm#Custom_Objects it's probably the most difficult documentation page in Autohotkey but it's very well explained.