Extending jQuery

Extending jQuery using Scala.js is done by extending the famous jQuery $ symbol. We can create a file named Notify.scala in the io.fscala.shopping.client package, in the client project.

In this file, we can first define the extension with the following piece of code:

@js.native
@JSGlobal("$")
object NotifyJS extends js.Object {
  def notify(msg: String, option: Options): String = js.native
}

An object named NotifyJS is defined, extending the Scala.js object named js.Object. It is necessary to inform the compiler that we are creating a facade of an existing JavaScript library.

The first annotation is @js.native; this annotation tells the compiler that the implementation is completely done in JavaScript. The second annotation ...

Get Scala Programming Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.