Root of the hierarchy of JavaScript types.
Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations.
Equivalent of scm.
Stores the JS constructor function of a JS class.
Creates a JavaScript Date instance that represents a single moment in time.
Dictionary "view" of a JavaScript value.
Dynamically typed JavaScript value.
An instance representing an error that occurs regarding the global function eval()
The Function constructor creates a new Function object.
ECMAScript 6 JavaScript Iterable.
Adapts a JavaScript Iterable to a Scala Iterable
ECMAScript 6 JavaScript Iterator.
Discouraged native JavaScript Array methods.
Operations on JavaScript numbers.
Operations on JavaScript strings.
Base class of all JavaScript objects.
ECMAScript 6 Promise of an asynchronous result.
An instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.
Represents an error when a non-existent variable is referenced.
The RegExp constructor creates a regular expression object for matching text with a pattern.
ECMAScript 6 JavaScript Symbol.
Represents an error when trying to interpret syntactically invalid code.
A thing on which one can call the then
method.
A JavaScript function where this
is considered as a first parameter.
A tuple "view" of 2 elements of a JavaScript Array.
A tuple "view" of 3 elements of a JavaScript Array.
Represents an error when a value is not of the expected type.
Represents an error when a malformed URI is encountered.
Value of type A or the JS undefined value.
A Unicode Normalization Form.
Helper for syntactic sugar of js.use.
Equivalent of scm.
Wrapper to use a js.
Marks the annotated class, trait or object as a native JS entity.
Value of type A or B (union type).
Marker trait for top-level objects representing the JS global scope.
Old-style base class for top-level, entry point main objects.
Provides implicit conversions from Scala values to JavaScript values.
Factory for js.Array objects.
Factory for js.Date objects.
Factory for Dictionary instances.
Factory for dynamically typed JavaScript values.
Provides implicit conversions and operations to write in JavaScript style with js.Dynamic.
A collection of decorators that allow converting Scala types to corresponding JS facade types
The JSON object contains methods for converting values to JavaScript Object Notation (JSON) and for converting JSON to values.
Math is a built-in object that has properties and methods for mathematical constants and functions.
The top-level Object
JavaScript object.
ECMAScript 6 Factory for js.Symbols and well-known symbols.
Methods related to URIs, provided by ECMAScript 5.
Factory for WrappedArray.
Returns the constructor function of a JavaScript class.
Returns the constructor function of a JavaScript class.
The specified type parameter T
must be a class type (i.e., valid for
classOf[T]
) and represent a class extending js.Any
(not a trait nor
an object).
Makes explicit an implicitly available ConstructorTag[T]
.
Evaluates JavaScript code and returns the result.
Evaluates JavaScript code and returns the result.
Tests whether the given value is undefined.
Tests whether the given value is undefined.
Denotes a method body as native JavaScript.
Denotes a method body as native JavaScript. For use in facade types:
class MyJSClass extends js.Object { def myMethod(x: String): Int = js.native }
Non-Standard Non-standard, but in general well supported methods to schedule asynchronous exeuction.
Returns the type of x
as identified by typeof x
in JavaScript.
ECMAScript 6 The typdearray package provides facade types for JavaScript ArrayBuffer, TypeArrays and DataView.
The undefined value.
The undefined value.
Allows to cast a value to a facade trait in a type-safe way.
Allows to cast a value to a facade trait in a type-safe way.
Use as follows:
js.use(x).as[MyFacade]
Note that the method calls are only syntactic sugar. There is no overhead
at runtime for such an operation. Using use(x).as[T]
is strictly
equivalent to x.asInstanceOf[T]
if the compile time check does not fail.
This method supports both Scala classes with exports and facade types which are structurally equivalent.
Given the following facade type:
trait MyFacade extends js.Object { def foo(x: Int): String = js.native val bar: Int = js.native }
We show a couple of examples:
class MyClass1 { @JSExport def foo(x: Int): String = x.toString @JSExport val bar: Int = 1 } val x1 = new MyClass1 js.use(x1).as[MyFacade] // OK
Note that JS conventions apply: The val bar
can be implemented with a
def
.
class MyClass2 { @JSExport def foo(x: Int): String = x.toString @JSExport def bar: Int = 1 // def instead of val } val x2 = new MyClass2 js.use(x2).as[MyFacade] // OK
Missing methods or methods with wrong types will cause a compile-time failure.
class MyClass3 { @JSExport def foo(x: String): String = x.toString // wrong type signature // bar is missing } val x3 = new MyClass3 js.use(x2).as[MyFacade] // Fails: bar is missing and foo has wrong type
Methods must be exported, otherwise they are not taken into consideration.
class MyClass4 { def foo(x: Int): String = x.toString @JSExport def bar: Int = 1 // def instead of val } val x4 = new MyClass4 js.use(x4).as[MyFacade] // Fails, foo is missing
Other facade types can also be used
trait MyOtherFacade extends js.Object { def foo(x: Any): String = js.native val bar: Int = js.native def otherMethod(): Unit = js.native } val x5: MyOtherFacade = // ... js.use(x5).as[MyFacade] // OK
Invokes any available debugging functionality.
Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.
MDN
Browser support:
(Since version 0.6.17) Use scala.scalajs.js.sepcial.debugger instead
Types, methods and values for interoperability with JavaScript libraries.
This package is only relevant to the Scala.js compiler, and should not be referenced by any project compiled to the JVM.
Guide
General documentation on Scala.js is available at http://www.scala-js.org/doc/.
Overview
The trait js.Any is the root of the hierarchy of JavaScript types. This package defines important subtypes of js.Any that are defined in the standard library of ECMAScript 5.1 (or ES 6, with a label in the documentation), such as js.Object, js.Array and js.RegExp.
Implicit conversions to and from standard Scala types to their equivalent in JavaScript are provided. For example, from Scala functions to JavaScript functions and back.
The most important subtypes of js.Any declared in this package are:
this
as an explicit parameterThe trait js.Dynamic is a special subtrait of js.Any. It can represent any JavaScript value in a dynamically-typed way. It is possible to call any method and read and write any field of a value of type js.Dynamic.
There are no explicit definitions for JavaScript primitive types, as one could expect, because the corresponding Scala types stand in their stead:
null
)Null
is the type of the JavaScript null valuejs.UndefOr gives a scala.Option-like interface where the JavaScript value
undefined
takes the role ofNone
.A | B is an unboxed pseudo-union type, suitable to type values that admit several unrelated types in facade types.