0

html中有一个JavaScript函数

<script type="text/javascript">
function someFunction(){
    return "<b>some text</b>";
}      

和 JSNI:

native String someFunction() /*-{
    return $wnd.someFunction();
}-*/;

问题是第一个脚本并非总是定义的。如果定义了函数,如何检查它?

先感谢您!

4

2 回答 2

2

您可以中继检查的返回布尔值defined,并执行以下操作:

native String someFunction() /*-{
    if ($wnd.someFunction) {
        return $wnd.someFunction();
    }
    return '';
}-*/;
于 2012-03-16T11:14:23.103 回答
0

我不熟悉 JSNI - 但在 JS 中你可以这样做:

if ( typeof someFunction == 'function' ) { ... }
于 2012-03-15T13:55:12.823 回答