Mic*_*ael 3 javascript gwt d3.js
如何在GWT中从JSNI 返回JavaScript 函数?我尝试了以下方式:
/* JSNI method returning a js-function */
public static native JavaScriptObject native_getFunction() /*-{
return function(a,b){
//do some stuff with a,b
}
}-*/;
Run Code Online (Sandbox Code Playgroud)
将函数存储在变量中
/* outside from GWT: store the function in a variable */
JavaScriptObject myFunction = native_getFunction();
Run Code Online (Sandbox Code Playgroud)
之后使用该函数会产生以下错误消息:
(TypeError): object is not a function
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
这适合我.声明这些方法:
public static native JavaScriptObject native_getFunction() /*-{
return function(a,b){
//do some stuff with a,b
}
}-*/;
private native void invoke(JavaScriptObject func)/*-{
func("a", "b");
}-*/;
Run Code Online (Sandbox Code Playgroud)
然后,您以这种方式使用这些方法:
JavaScriptObject func = native_getFunction();
invoke(func);
Run Code Online (Sandbox Code Playgroud)