Using Dart Classes from JavaScript

I have a Dart class (foo.dart):

class Foo {
  void talk() {
    print('Hello');
  }
}

      

After compiling foo.dart to JavaScript, I would like to use Foo like this:

var foo = new Foo(); // from foo.dart.js
foo.talk() // prints "Hello"

      

My questions:

  • Is it possible?
  • If so, how?
  • If not, what plans, if any, are in place to make this possible?

Dart documentation: js states :

This library does not yet make Dart objects usable by JavaScript, their methods and proeprties [sic] are not available, although it allows Dart functions to be passed and called from JavaScript.

That word "for now" gives some hope, but I've found very little elsewhere on this topic.

Edit:

I understand that it is possible to call Dart functions from JavaScript using dart2js. However, what I am trying to do is slightly different. I would like to be able to access all the functionality of the Dart class from JavaScript.

+2


source to share


1 answer


Due to tremors and mineralization, this is usually not possible. If you have a Dart application (c main()

, then you can make the Dart function callable from JavaScript (see How to call a Dart function from Javascript? For an example).

As far as I know, there are plans to support your claims, but I have no idea about the progress or when such a feature might be available.



This is a related project https://github.com/dart-lang/js-interop

+2


source







All Articles