1

I'm extending XMLHttpRequest in Scala.js:

class ReasonerHttpRequest(val reasonerId: String) extends XMLHttpRequest {}

Then, I try to create:

val http = new ReasonerHttpRequest(reasonerId)

This result in the following error:

TypeError: $g.ReasonerHttpRequest is not a constructor

What am I doing wrong? Thanks!

4
  • Do you have any compiler warning? If using Scala.js 0.6.x, did you add scalacOptions += "-P:scalajs:sjsDefinedByDefault" to your project's settings in sbt? Commented Jun 18, 2018 at 17:06
  • @sjrd That does not seem to make a difference. Anyway, my understanding is that this should not be necessary starting 0.6.17, and I'm using 0.6.23, the latest stable. Commented Jun 18, 2018 at 17:45
  • @sjrd Actually, it made one difference. The error now is: "TypeError: Constructor XMLHttpRequest requires 'new'" which makes no sense to me as I did use new. Commented Jun 18, 2018 at 17:47
  • It's probably because you cannot extend XMLHttpRequest with an ES 5.1 function+prototype. Try emitting ES 2015 code from Scala.js using scalaJSLinkerConfig ~= { _.withESFeatures(_.withUseECMAScript2015(true)) }. Note that this requires that your target browsers support ES 2015. Commented Jun 18, 2018 at 22:00

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.