Yes you can pass anything as
this if you do not want to use
this.
I mean in general
If you like, you can wrap your function lib in a super-class, which routes calls to the function lib, passing
this when appropriate. I use the
Foo-Bar notation since you started it, normally, when someone starts using more than 1 or 2
foos and
bars I stop reading,
Code: Select all
test(callback){
return callback.call()
}
class Foo {
; "function lib"
fooBar := "foo_bar" ; "static" variable
class _Foo{ ; the fn lib
bar(){
return "Hello world" "`n" this.foo()
}
foo(bar := 37){
return this.fooBar "`t" bar
}
}
; "Internal"
__new(){
Foo := this
return ""
}
__call(fn, foobars*){
static _Foo := Foo._Foo
return _Foo[fn].call(this, foobars*)
}
__get(foobars*){
static _Foo := Foo._Foo
return _Foo[foobars*].bind(Foo)
}
static __Foo := new Foo
}
msgbox % test(Foo.bar)
msgbox % test(Foo.foo)
msgbox % Foo.bar()
msgbox % Foo.foo()
msgbox % Foo.fooBar
fooFn := Foo.foo
msgbox % fooFn.call(3737)
msgbox % %fooFn%(373737)
As you can see, the user of the function lib can use it as it pleases,
Foo.bar(),
Foo.bar.Call() or
fooFn:=Foo.Bar then
fooFn.call() or
%fooFn%(). You can access "static" variables and other methods. There is one super-global variable,
Foo. I leave it as an exercise for you to ponder how to enable use of properties.
The usefulness of the above probably ends at the understanding of it.
Cheers and good luck.