Code: Select all
outer[p:=""] {
get {
; Define the period as a delimiter for v1 & v2 compatibility purposes.
static period := ".", _period := (A_AhkVersion < 2) ? period : "period"
; Finds the name of the outer class by recursively truncating this.__class.
; If this function is nested inside "default" then the outer class would be
; the name of the class that contains "default". Void if not nested in at least 2 classes.
if ((__outer := RegExReplace(this.__class, "^(.*)\..*$", "$1")) != this.__class)
Loop Parse, __outer, %_period%
outer := (A_Index=1) ? %A_LoopField% : outer[A_LoopField]
; Test if this property is nested in one class. If so, return the global class "p".
; Otherwise if the subclass p is not found or undefined, return an empty string.
if IsObject(outer)
return (p) ? outer[p] : outer
else
return (p) ? %p% : ""
}
}
inner[]
{
get {
; Gets a reference to the current class.
; Returns void if this function is not nested in a class.
if (_class := this.__class)
Loop, Parse, _class, .
inner := (A_Index=1) ? %A_LoopField% : inner[A_LoopField]
return inner
}
}
Code: Select all
a := new bird.owl()
a.outer.layEgg()
bird.owl.outer.owl.outer.sparrow.outer.owl.outer.sparrow.outer.layEgg()
class bird {
layEgg(){
text := "hi :)"
_text := (A_AhkVersion < 2) ? text : "text"
MsgBox %_text%
}
class owl extends default {
hoot(){
return "hoot!"
}
}
class sparrow extends default {
chirrup(){
return "chirrup!"
}
}
}
class default {
outer[p:=""] {
get {
; Define the period as a delimiter for v1 & v2 compatibility purposes.
static period := ".", _period := (A_AhkVersion < 2) ? period : "period"
; Finds the name of the outer class by recursively truncating this.__class.
; If this function is nested inside "default" then the outer class would be
; the name of the class that contains "default". Void if not nested in at least 2 classes.
if ((__outer := RegExReplace(this.__class, "^(.*)\..*$", "$1")) != this.__class)
Loop Parse, __outer, %_period%
outer := (A_Index=1) ? %A_LoopField% : outer[A_LoopField]
; Test if this property is nested in one class. If so, return the global class "p".
; Otherwise if the subclass p is not found or undefined, return an empty string.
if IsObject(outer)
return (p) ? outer[p] : outer
else
return (p) ? %p% : ""
}
}
}