我希望能够从Javascript中调用Dart函数。
我想使用dart2js(版本1.1.3)编译包含Dart函数的Dart脚本,然后将生成的.js文件加载到Javascript环境中,并从Javascript中调用该函数。
类似于从Javascript中调用下面的myHyperSuperMegaFunction。
我想使用dart2js(版本1.1.3)编译包含Dart函数的Dart脚本,然后将生成的.js文件加载到Javascript环境中,并从Javascript中调用该函数。
类似于从Javascript中调用下面的myHyperSuperMegaFunction。
import 'dart:js' as js;
int myHyperSuperMegaFunction(int a, int b) {
return a + b;
}
main() {
js.context['myHyperSuperMegaFunction'] = new js.JsFunction.withThis(myHyperSuperMegaFunction);
}
我尝试使用dart2js
编译以上内容,并将生成的.js
文件加载到Chrome中。变量myHyperSuperMegaFunction
已经被注册并定义为:
function () {
return _call(f, captureThis, this, Array.prototype.slice.apply(arguments));
}
然而,当我从Chrome Javascript控制台调用myHyperSuperMegaFunction(2,3)
时,我会收到以下错误:NoSuchMethodError:找不到方法:'Symbol("call")' Receiver: Instance of '(){this.$initialize' Arguments: [Instance of 'Window', 2, 3]