我想從Javascript調用飛鏢功能。如何從Javascript調用Dart函數?
我想使用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
文件到瀏覽器。可變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]