I know how Dart to use other javascript through dart.js library. How do I use Dart generated JavaScript in other JavaScript? How do I call a function in Dart generated javas
Using JS interop, you can call Javascript from Dart, and Dart from Javascript.
To call Dart from Javascript, you first need to register the functions that you want Javascript to have access to. It's also possible to pass primitives between JS and Dart and vice-versa.
import 'dart:html';
import 'dart:js' as js;
void main() {
js.context["myFunc"] = () {
print("called from javascript");
};
js.context["sayGreeting"] = (message) {
print("greeting: $message");
};
}
Then from Javascript, you can call the functions that you registered:
myFunc(); // prints 'called from javascript'
sayGreeting("Hello"); // prints 'greeting: Hello'