[a104] static __new triggered twice Topic is solved

Discuss the future of the AutoHotkey language
User avatar
aseiot
Posts: 33
Joined: 05 Mar 2017, 04:25

[a104] static __new triggered twice

21 Aug 2019, 18:24

Document wrote:Each class may also have a static __New method, which is called immediately after its static variables are initialized (this occurs in the order that classes are defined in the script). This method can be inherited from a base class, and can therefore be used to initialize subclasses. Within static __New, this refers to either the class which defined the method, or a subclass.
But I found it will be called twice upon initiation. Is that by design?

Code: Select all

class x
{
	static __New(){
		MsgBox "in __New"
	}
}
User avatar
aseiot
Posts: 33
Joined: 05 Mar 2017, 04:25

Re: [a104] static __new triggered twice  Topic is solved

22 Aug 2019, 18:05

Sorry, I found this happened when class is extends. In following code, __New will be called third times. So it is not a problem. :oops:

Code: Select all

class x
{
	static __New(){
		MsgBox "in __New"
	}
}
class y extends x
{
}
class z extends x
{
}

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: JoeWinograd and 20 guests