A mixin in a nested class.
Code: Select all
q := new uber.b
q.test()
try MsgBox % "Ground Level: " ObjRawGet(q, "__class") " Number of Objects: " q.Count()
try MsgBox % "Level -1: " ObjRawGet(q.base, "__class") " Number of Objects: " q.base.Count()
try MsgBox % "Level -2: " ObjRawGet(q.base.base, "__class") " Number of Objects: " q.base.base.Count()
for i, j in q
MsgBox % i " : " j
class uber {
class b {
mixin := this.__Mixin("a") ; NOTE THE STRING "a"
__Mixin(name){
try object := IsObject(name) ? name : %name%
if !IsObject(object) {
if ((_class := RegExReplace(this.__class, "^(.*)\..*$", "$1")) != this.__class)
Loop, Parse, _class, .
outer := (A_Index=1) ? %A_LoopField% : outer[A_LoopField]
object := outer[name]
}
; Import functions and data from the object.
__class := this.__class
for reference, subobject in object {
MsgBox % reference
if IsFunc(subobject)
this.base[reference] := ObjBindMethod(object, reference)
else
this[reference] := subobject
}
this.__class := __class
; Delete the mixin property (optional.)
self_remove := ObjBindMethod(this, "Remove", "mixin")
SetTimer, % self_remove, -1
}
}
class a {
test() {
MsgBox % "Foxy diva Jennifer Lopez wasn't baking my quiche."
}
}
}
Continued from... https://autohotkey.com/boards/viewtopic.php?f=6&t=54475 where I foolishly used inheritance even though it wasn't needed!