Skip to content

Commit e2325e4

Browse files
committed
Update the ScalaDoc of js.Any, js.UndefOr and the js package object.
With the introduction of js.| and Scala.js-defined JS classes, those ScalaDocs were outdated.
1 parent 7441caa commit e2325e4

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

library/src/main/scala/scala/scalajs/js/Any.scala

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,28 @@ import scala.collection.generic.CanBuildFrom
2121

2222
import annotation.ScalaJSDefined
2323

24-
/** Supertype of all JavaScript values.
24+
/** Root of the hierarchy of JavaScript types.
2525
*
26-
* Subtypes of [[Any js.Any]] are facade types to APIs implemented in
27-
* JavaScript code. Their implementation is irrelevant and never emitted.
28-
* As such, all members must be defined with their right-hand-side being
29-
* [[native js.native]].
26+
* Subtypes of [[Any js.Any]] are JavaScript types, which have different
27+
* semantics and guarantees than Scala types (subtypes of [[AnyRef]] and
28+
* [[AnyVal]]). Operations on JavaScript types behave as the corresponding
29+
* operations in the JavaScript language.
3030
*
31-
* In most cases, you should extend [[Object js.Object]] instead of this
32-
* trait to define facade types.
31+
* By default, JavaScript types are native: they are facade types to APIs
32+
* implemented in JavaScript code. Their implementation is irrelevant and
33+
* never emitted. As such, all members must be defined with their
34+
* right-hand-side being [[native js.native]]. For forward source
35+
* compatibility with the next major version, the class/trait/object itself
36+
* should be annotated with [[native @js.native]].
37+
*
38+
* In most cases, you should not directly extend this trait, but rather extend
39+
* [[Object js.Object]].
40+
*
41+
* To implement a JavaScript type in Scala.js (therefore non-native), its
42+
* declaration must be annotated with
43+
* [[annotation.ScalaJSDefined @ScalaJSDefined]]. Scala.js-defined JS types
44+
* cannot directly extend native JS traits; and Scala.js-defined JS traits
45+
* cannot declare concrete term members.
3346
*
3447
* It is not possible to define traits or classes that inherit both from this
3548
* trait and a strict subtype of [[AnyRef]]. In fact, you should think of

library/src/main/scala/scala/scalajs/js/UndefOr.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ package scala.scalajs.js
1212
import scala.language.implicitConversions
1313

1414
/** Value of type A or the JS undefined value.
15-
* In a type system with union types, this would really be
16-
* `A | js.prim.Undefined`. Since Scala does not have union types, but this
17-
* particular union is crucial to many interoperability scenarios, it is
18-
* provided as this trait.
1915
*
20-
* An API similar to that of [[scala.Option]] is provided through the
21-
* [[UndefOrOps]] implicit class, with the understanding that `undefined` is
22-
* the None value.
16+
* `js.UndefOr[A]` is the type of a value that can be either `undefined` or
17+
* an `A`. It provides an API similar to that of [[scala.Option]] through the
18+
* [[UndefOrOps]] implicit class, where `undefined` take the role of [[None]].
19+
*
20+
* By extension, this type is also suited to typing optional fields in native
21+
* JS types, i.e., fields that may not exist on the object.
2322
*/
2423
@scala.scalajs.js.annotation.RawJSType // Don't do this at home!
2524
sealed trait UndefOr[+A]
@@ -231,7 +230,7 @@ final class UndefOrOps[A](val self: UndefOr[A]) extends AnyVal {
231230
@inline final def toLeft[X](right: => X): Either[A, X] =
232231
if (isEmpty) Right(right) else Left(this.forceGet)
233232

234-
/** Returns a [[scala.Some]] containing this $options's value
233+
/** Returns a [[scala.Some]] containing this $option's value
235234
* if this $option is nonempty, [[scala.None]] otherwise.
236235
*/
237236
@inline final def toOption: Option[A] =

library/src/main/scala/scala/scalajs/js/package.scala

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,25 @@ package scala.scalajs
2222
*
2323
* == Overview ==
2424
*
25-
* The trait [[js.Any]] is the super type of all JavaScript values.
26-
*
27-
* All class, trait and object definitions that inherit, directly or
28-
* indirectly, from [[js.Any]] do not have actual implementations in Scala.
29-
* They are only the manifestation of static types representing libraries
30-
* written directly in JavaScript. It is not possible to implement yourself
31-
* a subclass of [[js.Any]]: all the method definitions will be ignored when
32-
* compiling to JavaScript.
25+
* The trait [[js.Any]] is the root of the hierarchy of JavaScript types.
26+
* This package defines important subtypes of [[js.Any]] that are defined
27+
* in the standard library of ECMAScript 5.1 (or ES 6, with a label in the
28+
* documentation), such as [[Object js.Object]], [[Array js.Array]] and
29+
* [[RegExp js.RegExp]].
3330
*
3431
* Implicit conversions to and from standard Scala types to their equivalent
3532
* in JavaScript are provided. For example, from Scala functions to JavaScript
3633
* functions and back.
3734
*
38-
* The most important subclasses of [[js.Any]] are:
39-
* - [[js.Dynamic]], a dynamically typed interface to JavaScript APIs
40-
* - [[js.Object]], the superclass of all statically typed JavaScript classes,
41-
* which has subclasses for all the classes standardized in ECMAScript 5.1,
42-
* among which:
43-
* - [[js.Array]]
44-
* - [[js.Function]] (and subtraits with specific number of parameters)
45-
* - [[js.ThisFunction]] and its subtraits for functions that take the
46-
* JavaScript `this` as an explicit parameters
47-
* - [[js.Dictionary]] to access the properties of an object in a
48-
* dictionary-like way
49-
* - [[js.Date]]
50-
* - [[js.RegExp]]
35+
* The most important subtypes of [[js.Any]] declared in this package are:
36+
* - [[Object js.Object]], the superclass of most (all) JavaScript classes
37+
* - [[Array js.Array]]
38+
* - [[Function js.Function]] (and subtraits with specific number of
39+
* parameters)
40+
* - [[ThisFunction js.ThisFunction]] and its subtraits for functions that
41+
* take the JavaScript `this` as an explicit parameter
42+
* - [[Dictionary js.Dictionary]], a [[Map]]-like view of the properties of a
43+
* JS object
5144
*
5245
* The trait [[js.Dynamic]] is a special subtrait of [[js.Any]]. It can
5346
* represent any JavaScript value in a dynamically-typed way. It is possible
@@ -56,14 +49,17 @@ package scala.scalajs
5649
*
5750
* There are no explicit definitions for JavaScript primitive types, as one
5851
* could expect, because the corresponding Scala types stand in their stead:
59-
* - [[Boolean]] is a primitive JavaScript boolean
60-
* - [[Double]] is a primitive JavaScript number
61-
* - [[String]] is a primitive JavaScript string
52+
* - [[Boolean]] is the type of primitive JavaScript booleans
53+
* - [[Double]] is the type of primitive JavaScript numbers
54+
* - [[String]] is the type of primitive JavaScript strings (or `null`)
6255
* - [[Unit]] is the type of the JavaScript undefined value
6356
* - [[Null]] is the type of the JavaScript null value
6457
*
65-
* [[js.UndefOr]] gives a [[scala.Option]]-like interface where the JavaScript
66-
* value `undefined` takes the role of `None`.
58+
* [[UndefOr js.UndefOr]] gives a [[scala.Option]]-like interface where the
59+
* JavaScript value `undefined` takes the role of `None`.
60+
*
61+
* [[| A | B]] is an unboxed pseudo-union type, suitable to type values that
62+
* admit several unrelated types in facade types.
6763
*/
6864
package object js {
6965
/** The undefined value. */

0 commit comments

Comments
 (0)