"outer" keyword - get a reference to the outer class (parent, super, root, inner)
Re: "outer" keyword - get a reference to the outer class (parent, super, root, inner)
I see - this is the first time I have seen base.method() being used. I just always misunderstood this part of the documentation.
Recommends AHK Studio
Re: "outer" keyword - get a reference to the outer class (parent, super, root, inner)
lexikos wrote:You can use this.base for that.
Actually using this.base gives me undesirable behavior...
Code: Select all
class a {
save(){
this.base.var := 7
}
}
a.save()
MsgBox % a.var ; blank
class b extends Empty {
save(){
this.base.var := 7
}
}
class Empty {
; Nothing to see here.
}
b.save()
MsgBox % b.var ; 7
; Expected, but undesirable behavior.
MsgBox % empty.var
Re: "outer" keyword - get a reference to the outer class (parent, super, root, inner)
Just use 'this' in that case...
Re: "outer" keyword - get a reference to the outer class (parent, super, root, inner)
Small update to the first post to address cases where the "outer" property is nested in one class. The user can now call this.outer["subclass"] to retrieve the global class named "subclass". This is useful when the class may or may not be nested inside another class.
Code: Select all
outer[p:=""] {
get {
; Determine if there is a parent class. this.__class will retrive the
; current instance's class name. Split the class string at each period,
; using array notation [] to dereference. Void if not nested in at least 2 classes.
if ((_class := RegExReplace(this.__class, "^(.*)\..*$", "$1")) != this.__class)
Loop, Parse, _class, .
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 no subclass (p) is specified, return an empty string.
if IsObject(outer)
return (p) ? outer[p] : outer
else
return (p) ? %p% : ""
}
}