scala-js/scala-js-dom

HashChangeEvent missing

tindzk opened this issue · 4 comments

There should be a HashChangeEvent. I defined it as follows:

case class HashChangeEvent(newURL: String, oldURL: String)
sjrd commented

Shouldn't it rather be

trait HashChangeEvent extends js.Object {
  val newURL: String
  val oldURL: String
}

?

What's the advantage of inheriting from js.Object?

sjrd commented

It's not a matter of advantage or disadvantage. If this represents a JavaScript object, it must inherit from js.Object, otherwise things will just blow up. The compiler treats differently types extending js.Object than those that do not.
See the doc about JavaScript interop.

Btw, it should even inherit from Event.

Ok, thanks for the information. I saw some Scala.JS code which used case classes in order to cast native objects to them. As this worked fine in my case, I thought that was the way to go.

By the way, I made a pull request with some additions a few weeks ago. Could you have a look at it?