Suggestion: Add static keyword before the current nested class

Discuss the future of the AutoHotkey language
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Suggestion: Add static keyword before the current nested class

Post by V2User » 06 Jan 2023, 00:37

@Lexicos
Dear Lexicos,
In my opinion, it would be much better than the current codes after adopting my suggestion like the below Code1.
Code1:

Code: Select all

class cls1 {
	__New() {
		this.cc:=77
	}
	static class ff    ; It is equivalent to the current nested class which is without static
	{
	}
	class ff  ; It will define a class-like method just like what happened in Python. It is completely equivalent to Code2 which is based on current V2.0.0.
	{
		static call(ths){
			OutputDebug(ths.cc)
		}
	}
}
c:=cls1()
c.ff()
Code2:

Code: Select all

#Requires AutoHotkey v2.0
class Cls1 {
	__New() {
		this.cc:=77
	}
}
cls1.Prototype.DefineProp('ff',{call:ff})
class ff {
	static call(ths){
		OutputDebug(ths.cc)
	}
}
c:=cls1()
c.ff()
As Cls1.ff:=ff can be replaced by static class ff nested in Cls1(which is without static at present). So, there is no reason that cls1.Prototype.DefineProp('ff',{call:ff}) can not also be replaced by "directly defining class-like method class ff{ in Cls1" just like what happened to static class ff{. It would truly become more consistent between class ff{ and static class ff{ if you could adopt my suggestion, perhaps in V2.x. Or you can just add static in front of class just for a reserve of potential future use.

Return to “AutoHotkey Development”