Replies: 3 comments 19 replies
-
Hmm, I'm confused how this works since the name used by the constructor is different from the class. Good question! @sjrd can you enlighten us please 😅 🙏 |
Beta Was this translation helpful? Give feedback.
-
My solution so far is this: import org.scalajs.dom.HTMLAudioElement
import scala.scalajs.js
def audio(url: String): HTMLAudioElement = {
js.Dynamic
.newInstance(js.Dynamic.global.Audio)(url)
.asInstanceOf[HTMLAudioElement]
}
def audio(): HTMLAudioElement = {
js.Dynamic
.newInstance(js.Dynamic.global.Audio)()
.asInstanceOf[HTMLAudioElement]
} |
Beta Was this translation helpful? Give feedback.
-
I think you'll want something similiar to the class Image(width: Int, height: Int) extends HTMLImageElement {
def this(width: Int) = this(width, 0)
def this() = this(0, 0)
} So maybe something like this( I am unsure how scala-js-dom deals with optional constructor values) class Audio(url: js.UndefOr[String] = js.native) extends HTMLAudioElement {} @armanbilge am I close with this? |
Beta Was this translation helpful? Give feedback.
-
https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio
How do I translate this to Scala.js DOM?
Beta Was this translation helpful? Give feedback.
All reactions