我在下面得到了这个 Dart 脚本,我想在使用 dart2js 编译 Dart 脚本后通过 JavaScript 访问类 hello_world 中的方法。有人知道这是如何工作的吗?!我已经知道如何访问诸如 foo(...) 之类的函数,这不是问题,但它与类和方法的工作方式不同。dartlang.org 上的教程只解释了如何访问函数,而不是方法和类。我不明白...
import 'dart:js' as js;
class hello_world {
String hello = 'Hello World!';
String getHello() {
print("getHello!!!!!");
return hello;
}
void ausgabe() {
print("Hallo Welt");
//return 0;
}
}
String foo(int n) {
print("hallo");
void foo2() {
print("hallo2");
}
//works
js.context['foo2'] = foo2;
return 'Hallo';
}
void main() {
int zahl1 = 3;
int zahl2 = 1234;
String w = 'test';
hello_world test = new hello_world();
//works
js.context['foo'] = foo;
}