On 22 mar, 23:42, Olivier Monaco <olivier.mon...@free.fr> wrote:
>
> The "call" method of a JavaScript function allows you to call it with
> a differente "this". Then, using "$wnd.js_callback.call(otherObject)",
> the "this" variable reference otherObject. So the glue is:
>
> var that = this;
> $wnd.js_callback = function() {
>     $entry(@mypackage.MyClass::MyMethod()).call(that);
>
> }
>
> When "js_callback" will be called, MyMethod is called on "that", the
> JavaScript object representing the MyClass instance. Finally, to avoid
> memory leaks of closure:
>
> $wnd.js_callback = (function(obj) {
>     return function() {
>         $entry(@mypackage.MyClass::MyMethod()).call(obj);
>     };
>
> })(this);

... or more simply:
var that = this;
$wnd.js_callback = $entry(function() { that.
@mypackage.MyClass::MyMethod()(); });

(this is what I should have written previously, sorry for the buggy
code)

As for the leak, are you sure there really is one once the code is
translated into JS? would it be better if the "inject" method were a
static one with the instance being passed as an argument (no use of
the "this"keyword within JSNI)?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to