Instead of explicitly passing the object to the parameter
this by using
call, you can define your own
this-parameter, for example,
Code: Select all
global obj := new C
obj.S.method1(obj) ; pass the invoking object, avoiding .call()
class C {
class S {
method1(self){
; 'this' refers to C.S
msgbox % self == obj
}
}
}
I think that is the simplest and clearest way to do it. Edit, but I would probably call it like
C.S.method1(obj)
You can also implement
__call, eg,
Code: Select all
global obj := new C
obj.method1()
class C {
class S {
method1(){
; no parameter refers to C.S
msgbox % this == obj
}
}
__call(m, p*){
if (C.S.haskey(m)) ; you can not call a in C, which has the same name as one in C.S
return C.S[m].call(this, p*)
}
}
This is also simple.
Cheers.