Closed jypma closed 5 months ago
The var
idiom is the new, better one. We should update the Scala.js docs if they still appear to recommend the val
idiom by default.
(abstract val
is good for non-optional members; optional ones are better served with a var ... = js.undefined
)
Ah, thanks a lot for clarifying! I guess it does make sense, JS objects are mutable either way. I suppose that inverts my original question ;-)
Most traits in
scala-js-dom
extendingjs.Object
useval
for their members, so they can be overridden selectively. See e.g.IDBCreateObjectStoreOptions
. This pattern is also recommended by the scalajs documentation:This allows a user to selectively override only some fields, e.g.
However,
dom.LockOptions
currently usesvar
. This means that this object needs to be instantiated asnew LockOptions {}
, and then the mutable fields can be changed.This makes
LockOptions
inconsistent with the other objects. However, changing it toval
would be a binary incompatible change, so I'm not sure of the proper way forward.