0

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?

2
  • 2
    Sure, 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. Commented Aug 2, 2017 at 15:44
  • Related: stackoverflow.com/questions/45245957/… Commented Aug 2, 2017 at 22:35

1 Answer 1

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!");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.