I have a bunch of Dart libraries that a customer wants to call from JavaScript. Is it possible to call functions created with dartdevc from JS?
Asked
Active
Viewed 145 times
0
-
2Sure, but DDC output is not intended to be used in production, it's only for development and for production still dart2js should be used. I have heard, that some actually use DDC for production, but it's not officially supported. `dart2js` output can't be called from JS except specific predefined entry-points. – Günter Zöchbauer Aug 02 '17 at 15:44
-
Related: https://stackoverflow.com/questions/45245957/compiling-dart-into-minifier-friendly-javascript-from-dartdevc-into-google-clos/45247781#45247781 – matanlurey Aug 02 '17 at 22:35
1 Answers
0
If you only want to call functions, you can probably do that in this way. Although I only know it's works for functions, probably not for whole class. I am also not sure about dartdevc support, but dart2js should be able to do this:
import 'dart:js' as js;
main() {
js.context['methodFromDart'] = doMyStuff;
}
void doMyStuff(String text) => print(text);
And then in you Javascript you are free to do:
methodFromDart("Hello world to Dart!");

tenhobi
- 1,977
- 3
- 23
- 49