scala-js-website
scala-js-website copied to clipboard
Document extending JavaScript interfaces
I believe after https://github.com/scala-js/scala-js-website/blob/master/doc/calling-javascript.md#defining-javascript-interfaces-with-traits it would be beneficial to show extending a Javascript interface. That way users can easily see how to enrich their JavaScript APIs with minimal work. I have provided an example below. However, I am sure a more useful example can be provided.
trait Window extends js.Object {
def alert(message: String): Unit = js.native
}
object Window {
implicit class RichWindow(val self: Window) extends AnyVal {
def help: Unit = self.alert("help")
}
}
Yes, it's probably worth documenting it. Although it's a fairly common general Scala idiom.
Yes, I agree with you. But it might be worth at least putting in an aside for people experimenting with scalajs who are not that familiar with Scala.
This is now documented in http://www.scala-js.org/doc/interoperability/facade-types.html
Is it? Searching implicit class
does not yield any result.
Ah, you are right, didn't look closely enough :)