我想从 Javascript 中调用 Dart 函数。
我想使用dart2js(版本 1.1.3)编译包含 Dart 函数的 Dart 脚本,然后将生成的.js文件加载到 Javascript 环境中并从 Javascript 调用该函数。
myHyperSuperMegaFunction类似于以下从 Javascript调用的内容。
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));
}
但是,当我myHyperSuperMegaFunction(2,3)从 Chrome Javascript 控制台调用时,出现以下错误NoSuchMethodError : method not found: 'Symbol("call")' Receiver: Instance of '(){this.$initialize' Arguments: [Instance of 'Window', 2, 3]