2

I know a lot changed since Using Dart classes from JavaScript

It is now possible to use dart classes inside Javascript?

I have some classes that call some APIs that I want to use in my Javascript app for the web.

8
  • Nothing has changed here - it is still not possible to call in to Dart code from JS at the top level without making functions available explicitly on the window or context Commented Jun 3, 2019 at 22:53
  • I found that dartdevc seems to output the code I want but the docs say I shouldn't use it. Even so, it complains about not knowing where dart_sdk is in const dart_sdk = require('dart_sdk') Commented Jun 4, 2019 at 10:34
  • You'd need to also include the dart_sdk.js file from the sdk to use DDC output. The specific copy depends on the options passed to DDC. Easiest way to use DDC is with build_runner and build_web_compilers. Note that DDC output is not guaranteed to be stable so we could change the calling conventions in a way that break calling in to it from js which is why we don't recommend it. Commented Jun 4, 2019 at 13:26
  • I've created a blank package using stagehand package-simple and I want to compile it to its JS counterpart. How does webdev build does it and I can't? Commented Jun 5, 2019 at 14:58
  • 1
    stackoverflow.com/a/21936509/374798 is still a supported route and works with dart2js. There is no supported way to call into Dart from js as a full class etc. It's probably possible but it's not documented or guaranteed to be stable. Commented Jun 5, 2019 at 19:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.