I was playing with function closures in GS2, trying to make them do something useful, and after hacking away at the callstack for awhile, I finally managed to do this.
PHP Code:
join("utility_bind");
//#CLIENTSIDE
function foobar(temp.a, temp.b) {
temp.c = 5;
temp.baz = function (temp.x) {
temp.scope = this.getScope();
return temp.scope.a + temp.scope.b + temp.scope.c + temp.x;
};
this.bind(temp.baz);
return temp.baz;
}
function onCreated() {
temp.f = this.foobar(5, 10);
echo(temp.f(5)); // echos 25
}
(Beware that copying this directly will add a space after every line, screwing up //#CLIENTSIDE)
Basically, you can bind the current state of the outer function (
foobar) to any function you pass (
temp.baz), and it will be immutable until the bound function executes
this.getScope() and stores it.
The magic is attached.
getCallStack() only works clientside in v6, so you'll need that to see this in action.