索引.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
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 版本:“linux_x64”上的 1.13.0-edge.a598fea28cf26ed82b0a197e65af33a7edca5cac(2015 年 10 月 15 日星期四 18:02:15)