rogp/jspp — Issue #16: automatic closures?
Author: CheloXL
Created: 2011-11-16 22:01:07+00:00
State: open

Take as example the following code:

```javascript
class foo {
public var b = 2;

public function fooMethod() {
return this.b;
}
}

class bar {
public function barMethod(method) {
return method();
}
}

var a = new foo();
var b = new bar();
alert(a.fooMethod());
alert(b.barMethod(a.fooMethod));
```

I would expect (I know I should not expect this in standard javascript) the second alert to also display 2 instead of undefined.

Maybe add an option to add automatic closures to public methods? So "this" always executes in the correct scope, instead of me having to do a method.apply(scope,...).

It is much easier to not have to keep track of both scope/method when passing methods along different classes. After all, when working with classes, this is the way anyone would expect it to work.