Learning scala.js and trying to export a scala.js class to javascript like this:
@JSExport("Pt")
class Pt[T]( points: Seq[T] ) {
@JSExport
def y = points(1)
}
When I tried this in javascript console (Chrome):
new Pt([1,2,3])
The above throws an error: "$c_sjsr_UndefinedBehaviorError ... 1,2,3 is not an instance of scala.collection.immutable.Seq". Not sure how I can pass a Seq as parameter in javascript.
What's the trick to create a class constructors with parameters, so that it can work as both javascript library and scala library? Do I have to use js.Array? (would prefer immutable collection if possible)
I tried @JSExportAll but it doesn't work either:
@JSExportAll
class Pt[T]( points: Seq[T] ) {
def y = points(1)
}
Then in javascript console (Chrome), I cannot even find the constructor function. It throws "ReferenceError: Pt is not defined"
js.Array[T], within your class then it can be used asSeq[T](probably you need to wrap it.) For constructors, you might be interested in this page.js.Array, then convert it to the immutableSeqfor use in the Scala code...