0

I would like to make references in native javascript based on names in strings in gwt:

private String reference = "testFunction";

private native void initTool() /*-{
  $wnd.reference = function(){ 
    //function action
  }
}-*/;

The idea then is that i from javascript should be able to run the method like this:

window.testFunction();

I hope this is possible some how? I havent found anything online explaining this, maybe because i dont know what to search for.

regards

Machavity
  • 30,841
  • 27
  • 92
  • 100
Esben Andersen
  • 802
  • 2
  • 9
  • 18
  • 1
    Did you have a look at this: [How to execute a JavaScript function when I have its name as a string](http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string)? – Baz Apr 04 '14 at 09:27

2 Answers2

2
$wnd[this.@my.app.client.MyClass::reference] = function() { … }
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
0

No you cannot .

What you can do is pass the String to JavaScript and decide the function name there based upon conditions.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307