Hi Andrey,
The last solution that Thomas and sutarsa girl proposed should do the trick
(assigning the var to the 'this' variable before referencing functions from
it). The reason why this must be done to make sure that the copy of the
'this' object that you're dealing with is what you expect it to be. The
'this' variable in an inner function is part of a closure, and in closures,
the 'this' variable is stored by reference. Therefore, the state of the
'this' object at the time you're accessing it isn't guaranteed, and hence
your function call might not work. By assigning a var to 'this' and then
calling the function from that var, you're guaranteed that the function is
defined and the var is what you think it is.

This is described in the FAQ linked below:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_BridgeMethodNotWorkingOnclick

Hope that helps,
-Sumit Chandel

On Sun, Mar 1, 2009 at 8:48 PM, sutarsa giri <sutarsa.g...@gmail.com> wrote:

> hi andrey,
> i usually use this trick when deal with this reference inside method
>
>
> class PageToolbar extends PagingToolbar {
> private native void patch() /*-{
>        var dummyThis=this;
>        var pagingToolbar =
> th...@com.gwtext.client.widgets.component::getOrCreateJsObj()();
>
>        pagingToolbar.field.on("keydown", function(e) {
>                alert("1");
>                *dummythi...@mypackage.pagetoolbar::mymethod()();
>                alert("2");
>        }, pagingToolbar);
> }-*/;
> private void mymethod() {
>  ...
> }
> }
>
>
>
> it's work for my jsni call
>
>
> On Mon, Mar 2, 2009 at 7:42 AM, Shawn Brown <big.coffee.lo...@gmail.com>wrote:
>
>>
>> HI,
>>
>> > Is there any way I can access enclosing "this"
>> > instance (that would be PageToolbar)?
>>
>> Pass it in, and call your method. It works for me.
>>
>> patch(this);  //method call
>>
>> class PageToolbar extends PagingToolbar {
>> private native void patch(PageToolbar pt) /*-{  /class of whatever
>> gets passed in
>>       var pagingToolbar =
>> p...@com.gwtext.client.widgets.component::getOrCreateJsObj()();
>>
>>       pagingToolbar.field.on("keydown", function(e) {
>>               alert("1");
>>               p...@mypackage.pagetoolbar::mymethod()();
>>                alert("2");
>>       }, pagingToolbar);
>> }-*/;
>> private void mymethod() {
>>  ...
>> }
>> }
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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-Toolkit@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