的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>
index.dart
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([]));
}
Dart VM版本:1.13.0-edge.a598fea28cf26ed82b0a197e65af33a7edca5cac(2015年10月15日星期四18:02:15)&#34; linux_x64&#34;
答案 0 :(得分:2)
按预期工作。
我刚刚在Dart更新期间运行了Dartium,并且在我尝试该示例时仍然运行旧版本。关闭并重新打开Dartium之后,代码运行良好。