0

I have a GWT class with two JSNI JavaScript functions. I want to call one function inside another, like this:

public class MyClass
{
  public native void Function1()
  /*-{
    console.log("Function 1");
  }-*/;

  public native void Function2()
  /*-{
    Function1();
  }-*/;
}

In this case, when executing Function2 i'm getting "Function1 is not defined".

Keep in mind that I don't want to embeed Function1 inside Function2 code, I need two different JSNI functions (so I can call Function1 from multiple functions).

Thank you.

2 Answers 2

1

change the two methods to be static also.
you can simply call any method from your jsni code like this:

public class MyClass
{
  public static native void Function1()
  /*-{
    console.log("Function 1");
  }-*/;

  public static native void Function2()
  /*-{
    @xxx.xxxxx.xxxx.MyClass::Function1();
  }-*/;
}

more information can be found here.

Sign up to request clarification or add additional context in comments.

3 Comments

you can also call a non static function
then you have to use this
Thank you both, this is just what I was looking for.
1
package mypackage;  

public class Account {
    private int balance = 0;

 public int add(int amt) {
      balance += amt;
   }

public native void exportAdd() /*-{
    var that = this;
    [email protected]::add(I)(10);
}-*/;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.