JavaSscript:
class MyClass {
constructor() {
console.log("MyClass instance created");
this.answer = 42;
}
}
let example = new MyClass();
console.log(example.answer);
Dart:
@JS()
library interop_test;
import 'package:js/js.dart';
@JS()
class MyClass {
external int get answer;
external set answer(int value);
}
Creating an instance of the the interop class MyClass
as
MyClass myClass = MyClass();
results in:
EXCEPTION: TypeError: dart.global.MyClass is not a constructor
I've also tried to add a external MyClass();
and external factory MyClass();
to the @JS()
annotated class, but got the same message. If I add @anonymous
annotation to the interop class, the exception goes away, but I can't access instance members. (But I don't see why this would need the anonymous annotation)
I'm using dart 2.0.0
, angular 5.0.0
, js 0.6.1+1
and dartdevc
through webdev
.