Code: Select all
Class C {
prop := 7
__Init() {
var := "test"
}
} ; Error at line 148. Line Text: __Init Error: Duplicate declaration. The program will exit.
> Doesn't work: duplicate declaration due to the
prop instance variable declaration:
documentation wrote:These declarations are evaluated each time a new instance of the class is created with the new keyword. The method name __Init is reserved for this purpose (...)
Code: Select all
Class C {
__Init() {
this.prop := A_NowUTC
}
__New() {
MsgBox % this.prop
}
}
K1 := new C()
sleep, 1000
K2 := new C()
>It appears that this works - however the documentation asserts that
[__init method] should not be used by the script
Code: Select all
Class C {
static dependencies :=[ A_ScriptDir . "\settings.ini", A_ScriptDir . "\HTMLFile.html"]
prop := 7
Init() { ; works
static __ := C.init()
for __index, __file in C.dependencies
if not (FileExist(__file)) {
C.exception := __index
ExitApp
}
}
__New() {
MsgBox % A_ThisFunc
}
exception {
set {
MsgBox, 16, Initialization error, The program will exit. Specifically: %value%
}
}
}
K := new C()
> Works since the method name doesn't start with two underlines; it is not a meta-function.