Supertype of all JavaScript values.
Supertype of all JavaScript values.
Subtypes of js.Any are facade types to APIs implemented in JavaScript code. Their implementation is irrelevant and never emitted. As such, all members must be defined with their right-hand-side being js.native.
In most cases, you should extend js.Object instead of this trait to define facade types.
It is not possible to define traits or classes that inherit both from this trait and a strict subtype of AnyRef. In fact, you should think of js.Any as a third direct subclass of scala.Any, besides scala.AnyRef and scala.AnyVal.
See the JavaScript interoperability guide of Scala.js for more details.
Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations.
Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed. Since an array's size length grow or shrink at any time, JavaScript arrays are not guaranteed to be dense. In general, these are convenient characteristics; but if these features are not desirable for your particular use, you might consider using typed arrays.
MDN
To construct a new array with uninitialized elements, use the constructor of this class. To construct a new array with specified elements, as if you used the array literal syntax in JavaScript, use the Array.apply method instead.
Type of the elements of the array
Equivalent of scm.ArrayOps for js.Array
Equivalent of scm.ArrayOps for js.Array
Creates a JavaScript Date instance that represents a single moment in time.
Creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC.
MDN
Dictionary "view" of a JavaScript value.
Dictionary "view" of a JavaScript value.
Using objects as dictionaries (maps from strings to values) through their properties is a common idiom in JavaScript. This trait lets you treat an object as such a dictionary, with the familiar API of a Map.
To use it, cast your object, say x
, into a Dictionary using
val xDict = x.asInstanceOf[js.Dictionary[Int]]
then use it as
xDict("prop") = 5 println(xDict.get("prop")) // displays Some(5) xDict -= "prop" // removes the property "prop" println(xDict.get("prop")) // displays None
To enumerate all the keys of a dictionary, use collection methods or for comprehensions. For example:
for ((prop, value) <- xDict) { println(prop + " -> " + value) }
Note that this does not enumerate properties in the prototype chain of
xDict
.
This trait extends js.Any directly, because it is not safe to call methods of js.Object on it, given that the name of these methods could be used as keys in the dictionary.
Dynamically typed JavaScript value.
Dynamically typed JavaScript value.
Values of this trait accept all possible JavaScript operations in a dynamically typed way. You can read and write any field, call any method, apply any JavaScript operator to values of this type.
An instance representing an error that occurs regarding the global function eval()
An instance representing an error that occurs regarding the global function eval()
MDN
The Function constructor creates a new Function object.
The Function constructor creates a new Function object. In JavaScript every function is actually a Function object.
Function objects created with the Function constructor are parsed when the function is created. This is less efficient than declaring a function and calling it within your code, because functions declared with the function statement are parsed with the rest of the code.
All arguments passed to the function are treated as the names of the identifiers of the parameters in the function to be created, in the order in which they are passed.
Note: Functions created with the Function constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the Function constructor was called. This is different from using eval with code for a function expression.
Invoking the Function constructor as a function (without using the new operator) has the same effect as invoking it as a constructor.
MDN
Marker trait for top-level objects representing the JS global scope.
Marker trait for top-level objects representing the JS global scope.
When calling method on a top-level object or package object that is a subtype of GlobalScope, the receiver is dropped, and the JavaScript global scope is used instead.
Base class for top-level, entry point main objects.
Base class for top-level, entry point main objects.
Objects inheriting from JSApp are automatically exported to JavaScript under their fully qualified name, and their main method as well.
JSApp is typically used to mark the entry point of a Scala.js
application. As such, the sbt plugin also recognizes top-level objects
extending JSApp. It allows to run their main method with sbt run
,
and can also generate a tiny JavaScript launcher snippet executing the
main method of one specific JSApp object.
Discouraged native JavaScript Array methods.
Discouraged native JavaScript Array methods.
In general, you should prefer the Scala collection methods available implicitly through ArrayOps, because they are inlineable, and hence faster.
To enable the use of these functions on js.Arrays, import the implicit conversion JSArrayOps.jsArrayOps.
Operations on JavaScript numbers.
Operations on JavaScript numbers.
Operations on JavaScript strings.
Operations on JavaScript strings.
The methods with an equivalent signature in String but with a different
meaning are prefixed by js
in this trait.
Base class of all JavaScript objects.
Base class of all JavaScript objects.
An instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.
An instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.
A RangeError is thrown when trying to pass a number as an argument to a function that does not allow a range that includes that number. This can be encountered when to create an array of an illegal length with the Array constructor, or when passing bad values to the numeric methods toExponential, toFixed, or toPrecision.
MDN
Represents an error when a non-existent variable is referenced.
Represents an error when a non-existent variable is referenced.
A ReferenceError is thrown when trying to dereference a variable that has not been declared.
MDN
The RegExp constructor creates a regular expression object for matching text with a pattern.
The RegExp constructor creates a regular expression object for matching text with a pattern.
MDN
Represents an error when trying to interpret syntactically invalid code.
Represents an error when trying to interpret syntactically invalid code.
A SyntaxError is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language when parsing code.
MDN
A JavaScript function where this
is considered as a first parameter.
A JavaScript function where this
is considered as a first parameter.
Represents an error when a value is not of the expected type.
Represents an error when a value is not of the expected type.
A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.
MDN
Represents an error when a malformed URI is encountered.
Represents an error when a malformed URI is encountered.
A URIError is thrown when the URI handling functions are passed a malformed URI.
MDN
Value of type A or the JS undefined value.
Value of type A or the JS undefined value.
In a type system with union types, this would really be
A | js.prim.Undefined
. Since Scala does not have union types, but this
particular union is crucial to many interoperability scenarios, it is
provided as this trait.
An API similar to that of scala.Option is provided through the
UndefOrOps implicit class, with the understanding that undefined
is
the None value.
Equivalent of scm.WrappedArray for js.Array
Equivalent of scm.WrappedArray for js.Array
Wrapper to use a js.Dictionary as a scala.mutable.Map
Wrapper to use a js.Dictionary as a scala.mutable.Map
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.
Provides implicit conversions and operations to write in JavaScript style with js.Dynamic.
Be **very** careful when importing members of this object. You may want to selectively import the implicits that you want to reduce the likelihood of making mistakes.
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.
The JSON object contains methods for converting values to JavaScript Object Notation (JSON) and for converting JSON to values.
MDN
Math is a built-in object that has properties and methods for mathematical constants and functions.
Math is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.
MDN
The top-level Object
JavaScript object.
Methods related to URIs, provided by ECMAScript 5.1.
$factoryInfo
Invokes any available debugging functionality.
Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.
MDN
Browser support:
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.
Non-Standard Non-standard, but in general well supported methods to schedule asynchronous exeuction.
The methods in this package work in all JavaScript virtual machines supported by Scala.js (currently Rhino, Node.js and PhantomJS).
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.
ECMAScript 6 The typdearray package provides facade types for JavaScript ArrayBuffer, TypeArrays and DataView. Further, it provides conversions between primitive Scala arrays and TypedArrays
The undefined value.
The undefined value.
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 super type of all JavaScript values.
All class, trait and object definitions that inherit, directly or indirectly, from js.Any do not have actual implementations in Scala. They are only the manifestation of static types representing libraries written directly in JavaScript. It is not possible to implement yourself a subclass of js.Any: all the method definitions will be ignored when compiling to JavaScript.
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 subclasses of js.Any are:
this
as an explicit parametersThe 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:
js.UndefOr gives a scala.Option-like interface where the JavaScript value
undefined
takes the role ofNone
.