You need to "bind" the method to the instance, e.g.
$wnd.log = $entry(function(msg) {
[email protected]::log(Ljava/lang/String;)(msg); });
Note that 'instance' cannot be 'this' here, because 'this' is a keyword,
not a variable. You could for instance pass your 'this' as argument to the
export() method so you have a variable pointing to your instance, or you
could just store your instance in a variable outside the closure:
var that = this;
$wnd.log = $entry(function(msg) {
[email protected]::log(Ljava/lang/String;)(msg); });
On Saturday, February 15, 2014 7:51:13 AM UTC+1, rjcarr wrote:
>
> The subject sums it up pretty well, so let's get right to code:
>
> public class Main implements EntryPoint {
> public void onModuleLoad() {
> export();
> }
>
> public void log(String msg) {
> ...
> }
>
> public static native void export() /*-{
> $wnd.log = $entry([email protected]::log(Ljava/lang/String));
>
> }-*/;
>
> This doesn't work for me and I get giant stack traces in my javascript
> logs. I got this idea from the JSNI docs so not sure where I'm going
> wrong. However, if I change things to this:
>
> public class Main implements EntryPoint {
> public void onModuleLoad() {
> export();
> }
>
> public static void log(String msg) {
> ...
> }
>
> public static native void export() /*-{
> $wnd.log = $entry(@package.Main::log(Ljava/lang/String));
>
> }-*/;
>
> Then it works fine. What am I doing wrong? Thanks!
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.