GWT JSNI返回一个js函数 [英] GWT JSNI return a js-function
本文介绍了GWT JSNI返回一个js函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在GWT中从JSNI返回JavaScript 函数?我尝试了以下方式:
How can I return a JavaScript function from JSNI in GWT? I tried it the following way:
/* JSNI method returning a js-function */
public static native JavaScriptObject native_getFunction() /*-{
return function(a,b){
//do some stuff with a,b
}
}-*/;
将函数存储在变量中
/* outside from GWT: store the function in a variable */
JavaScriptObject myFunction = native_getFunction();
之后使用该函数会产生以下错误消息:
Using the function afterwards produces the following error message:
(TypeError): object is not a function
有人知道如何解决这个问题吗?
Does somebody know how to solve this problem?
推荐答案
声明这些方法:
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");
}-*/;
然后,使用这些方法:
JavaScriptObject func = native_getFunction();
invoke(func);
这篇关于GWT JSNI返回一个js函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文