Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 如何使用新的JS(0.6.0)包调用JS函数_Dart_Dart Js Interop - Fatal编程技术网

Dart 如何使用新的JS(0.6.0)包调用JS函数

Dart 如何使用新的JS(0.6.0)包调用JS函数,dart,dart-js-interop,Dart,Dart Js Interop,index.html <!doctype html> <html> <head> <script> var testFunction = function() {return 'xxx'}; </script> </head> <body> <script type="application/dart" src="index.dart"></scr

index.html

<!doctype html>
<html>
  <head>
    <script>
      var testFunction = function() {return 'xxx'};
    </script>
  </head>
  <body>
    <script type="application/dart" src="index.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </body>
</html>
Dart虚拟机版本:1.13.0-edge.a598fea28cf26ed82b0a197e65af33a7edca5cac(2015年10月15日星期四18:02:15)在“linux x64”上

一切正常


我只是在Dart更新期间运行了Dartium,在我尝试该示例时仍在运行旧版本。关闭并重新打开Dartium后,代码运行良好

请使用问题的编辑链接添加其他信息。“发布答案”按钮只能用于问题的完整答案。实际上,它是一个完整的答案。问题中的代码工作正常,浏览器版本太旧,无法支持代码中使用的功能。我考虑结束这个问题,但决定反对,因为我认为这可能对其他人有用。我更新了我的答案。
import 'dart:js' as js;
import 'package:js/js.dart';

@Js() // about to being changed to @JS
external String testFunction();

main() {
  // fails: Exception: Uncaught Error: No top-level method 'testFunction' declared.
  print(testFunction()); 

  // works
  print((js.context['testFunction'] as js.JsFunction).apply([]));
}