Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tee class
cls := new TeeClasses(MyClass, MyOtherClass)
inst := new cls()
inst.MyMethod("a","b") ; this calls MyMethod from *both* classes
class MyClass
{
MyMethod(arg1, arg2)
{
msgbox % A_ThisFunc " called with: " arg1 ", " arg2
}
}
class MyOtherClass
{
MyMethod(arg1, arg2)
{
msgbox % A_ThisFunc " called with: " arg1 ", " arg2
}
}
class TeeClasses
{
__New(classes*)
{
obj := {}
cls := this.__class "("
for k,c in classes
cls .= c.__class ","
obj.__class := SubStr(cls, 1, -1) ")"
obj.__new := Tee.new
obj.__call := Tee.call
obj.__bases := classes
; return a new, dynamically created class
return obj
}
new(args*)
{
Tee.call.(this, "__new", args*)
}
call(fn, args*)
{
for k,v in this.__bases
if ObjHasKey(v, fn)
v[fn].(this, args*)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment