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
  • 29,816
  • 26
  • 86
  • 96
Esben Andersen
  • 781
  • 2
  • 8
  • 17
  • 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

1
$wnd[this.@my.app.client.MyClass::reference] = function() { … }
Thomas Broyer
  • 64,173
  • 7
  • 89
  • 163
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
  • 118,038
  • 37
  • 189
  • 297