Consider v1:
Code: Select all
class Application
{
class Helper
{
SOME_PROPERTY1 := 1
SOME_PROPERTY2 := 2
InstanceMethod()
{
return this.SOME_PROPERTY1 + this.SOME_PROPERTY2
}
}
}
Code: Select all
class Application {
class Helper {
static SOME_PROPERTY1 := 1
static SOME_PROPERTY2 := 2
InstanceMethod() {
return Application.Helper.SOME_PROPERTY1 + Application.Helper.SOME_PROPERTY2
}
}
}
A common pattern I used in v1 was to nest libraries. For this example, that would be to have Application as one file Application.ahk, and Helper as a different file Helper.ahk, then to write Application.ahk as
Code: Select all
class Application {
...
...
...
#IncludeAgain %A_LineFile%\..\Helper.ahk
}
*Future module support may offer an alternate path to address this problem
However, combining this strategy with AHKv2 makes using statics very difficult as the library to be nested (my JSON library) would need to code in the name(s) of any parent classes, which just isn't possible to know ahead of time.
To combat this, I've considered adding this property definition to my libraries (maybe not applied to the base Class, but to each of my libraries individually):
Code: Select all
Class.Prototype.base.DefineProp("__Static", {get: classStaticGet})
classStaticGet(this) {
for name in StrSplit(this.__Class,".")
obj := IsSet(obj) ? obj.%name% : %name%
return obj
}
Code: Select all
class Application {
class Helper {
static SOME_PROPERTY1 := 1
static SOME_PROPERTY2 := 2
InstanceMethod() {
return this.__Static.SOME_PROPERTY1 + this.__Static.SOME_PROPERTY2
}
}
}
With that context in mind, what I would like to see is a __Static property be added natively to the Class object, to eliminate the tradeoffs.
Furthermore, a new operator of :: which automatically accesses the __Static property, similar to how . accesses __Get, would be a fantastic addition to reduce clutter, allowing people to write this::SOME_PROPERTY rather than this.__Static.SOME_PROPERTY.