我在下面得到了这个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;
}发布于 2014-03-12 21:53:57
假设您想要在Dart方法上创建一个Js函数绑定,您可以执行几乎相同的操作:
void main() {
hello_world test = new hello_world();
// define a 'getHelloOnTest' Js function
js.context['getHelloOnTest'] = test.getHello;
}现在,在Js端,您可以使用:
getHelloOnTest();https://stackoverflow.com/questions/22351766
复制相似问题