scala.scalajs

js

package js

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:

The 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 of None.

Linear Supertypes
AnyRef, scala.Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. js
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. trait Any extends AnyRef

    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.

    Annotations
    @RawJSType()
  2. class Array[A] extends Object

    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.

    A

    Type of the elements of the array

    Annotations
    @RawJSType()
  3. final class ArrayOps[A] extends ArrayLike[A, Array[A]] with Builder[A, Array[A]]

    Equivalent of scm.ArrayOps for js.Array

    Equivalent of scm.ArrayOps for js.Array

    Annotations
    @inline()
  4. class Date extends Object

    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

    Annotations
    @RawJSType()
  5. sealed trait Dictionary[A] extends Any

    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.

    Annotations
    @RawJSType()
  6. sealed trait Dynamic extends Any with scala.Dynamic

    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.

    Annotations
    @RawJSType()
  7. class Error extends Object

    Annotations
    @RawJSType()
  8. class EvalError extends Error

    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

    Annotations
    @RawJSType()
  9. class Function extends Object

    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

    Annotations
    @RawJSType()
  10. trait Function0[+R] extends Function

    Annotations
    @RawJSType()
  11. trait Function1[-T1, +R] extends Function

    Annotations
    @RawJSType()
  12. trait Function10[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, +R] extends Function

    Annotations
    @RawJSType()
  13. trait Function11[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, +R] extends Function

    Annotations
    @RawJSType()
  14. trait Function12[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, +R] extends Function

    Annotations
    @RawJSType()
  15. trait Function13[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, +R] extends Function

    Annotations
    @RawJSType()
  16. trait Function14[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, +R] extends Function

    Annotations
    @RawJSType()
  17. trait Function15[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, +R] extends Function

    Annotations
    @RawJSType()
  18. trait Function16[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, +R] extends Function

    Annotations
    @RawJSType()
  19. trait Function17[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, +R] extends Function

    Annotations
    @RawJSType()
  20. trait Function18[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, +R] extends Function

    Annotations
    @RawJSType()
  21. trait Function19[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, +R] extends Function

    Annotations
    @RawJSType()
  22. trait Function2[-T1, -T2, +R] extends Function

    Annotations
    @RawJSType()
  23. trait Function20[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, +R] extends Function

    Annotations
    @RawJSType()
  24. trait Function21[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, +R] extends Function

    Annotations
    @RawJSType()
  25. trait Function22[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, -T22, +R] extends Function

    Annotations
    @RawJSType()
  26. trait Function3[-T1, -T2, -T3, +R] extends Function

    Annotations
    @RawJSType()
  27. trait Function4[-T1, -T2, -T3, -T4, +R] extends Function

    Annotations
    @RawJSType()
  28. trait Function5[-T1, -T2, -T3, -T4, -T5, +R] extends Function

    Annotations
    @RawJSType()
  29. trait Function6[-T1, -T2, -T3, -T4, -T5, -T6, +R] extends Function

    Annotations
    @RawJSType()
  30. trait Function7[-T1, -T2, -T3, -T4, -T5, -T6, -T7, +R] extends Function

    Annotations
    @RawJSType()
  31. trait Function8[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, +R] extends Function

    Annotations
    @RawJSType()
  32. trait Function9[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, +R] extends Function

    Annotations
    @RawJSType()
  33. trait GlobalScope extends Any

    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.

    Annotations
    @RawJSType()
    See also

    Calling JavaScript from Scala.js

  34. trait JSApp extends AnyRef

    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.

    Annotations
    @JSExportDescendentObjects()
  35. trait JSArrayOps[A] extends 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.

    Annotations
    @RawJSType()
  36. trait JSNumberOps extends Any

    Operations on JavaScript numbers.

    Operations on JavaScript numbers.

    Annotations
    @RawJSType()
  37. trait JSStringOps extends Any

    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.

    Annotations
    @RawJSType()
  38. case class JavaScriptException(exception: scala.Any) extends RuntimeException with Product with Serializable

  39. trait LowPrioAnyImplicits extends AnyRef

  40. class Object extends Any

    Base class of all JavaScript objects.

    Base class of all JavaScript objects.

    Annotations
    @RawJSType()
  41. trait PropertyDescriptor extends Object

    Annotations
    @RawJSType()
  42. class RangeError extends Error

    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

    Annotations
    @RawJSType()
  43. class ReferenceError extends Error

    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

    Annotations
    @RawJSType()
  44. class RegExp extends Object

    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

    Annotations
    @RawJSType()
  45. class SyntaxError extends Error

    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

    Annotations
    @RawJSType()
  46. trait ThisFunction extends Function

    A JavaScript function where this is considered as a first parameter.

    A JavaScript function where this is considered as a first parameter.

    Annotations
    @RawJSType()
    See also

    Calling JavaScript from Scala.js

  47. trait ThisFunction0[-T0, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  48. trait ThisFunction1[-T0, -T1, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  49. trait ThisFunction10[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  50. trait ThisFunction11[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  51. trait ThisFunction12[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  52. trait ThisFunction13[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  53. trait ThisFunction14[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  54. trait ThisFunction15[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  55. trait ThisFunction16[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  56. trait ThisFunction17[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  57. trait ThisFunction18[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  58. trait ThisFunction19[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  59. trait ThisFunction2[-T0, -T1, -T2, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  60. trait ThisFunction20[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  61. trait ThisFunction21[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  62. trait ThisFunction3[-T0, -T1, -T2, -T3, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  63. trait ThisFunction4[-T0, -T1, -T2, -T3, -T4, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  64. trait ThisFunction5[-T0, -T1, -T2, -T3, -T4, -T5, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  65. trait ThisFunction6[-T0, -T1, -T2, -T3, -T4, -T5, -T6, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  66. trait ThisFunction7[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  67. trait ThisFunction8[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  68. trait ThisFunction9[-T0, -T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, +R] extends Function with ThisFunction

    Annotations
    @RawJSType()
  69. class TypeError extends Error

    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

    Annotations
    @RawJSType()
  70. class URIError extends Error

    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

    Annotations
    @RawJSType()
  71. sealed trait UndefOr[+A] extends AnyRef

    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.

    Annotations
    @RawJSType()
  72. final class UndefOrOps[A] extends AnyVal

  73. final class WrappedArray[A] extends AbstractBuffer[A] with GenericTraversableTemplate[A, WrappedArray] with collection.mutable.IndexedSeq[A] with BufferLike[A, WrappedArray[A]] with ArrayLike[A, WrappedArray[A]] with Builder[A, WrappedArray[A]]

    Equivalent of scm.WrappedArray for js.Array

    Equivalent of scm.WrappedArray for js.Array

    Annotations
    @inline()
  74. class WrappedDictionary[A] extends AbstractMap[String, A] with Map[String, A] with MapLike[String, A, WrappedDictionary[A]]

    Wrapper to use a js.Dictionary as a scala.mutable.Map

    Wrapper to use a js.Dictionary as a scala.mutable.Map

    Annotations
    @inline()

Value Members

  1. object Any extends LowPrioAnyImplicits

    Provides implicit conversions from Scala values to JavaScript values.

  2. object Array extends Object

    Factory for js.Array objects.

  3. object ArrayOps

  4. object Date extends Object

    Factory for js.Date objects.

  5. object Dictionary

    Factory for Dictionary instances.

  6. object Dynamic

    Factory for dynamically typed JavaScript values.

  7. object DynamicImplicits

    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.

  8. object Error extends Object

  9. object EvalError extends Object

  10. object Function extends Object

  11. object JSArrayOps

  12. object JSConverters

    A collection of decorators that allow converting Scala types to corresponding JS facade types

  13. object JSNumberOps

  14. object JSON extends Object

    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

  15. object JSStringOps

  16. object Math extends Object

    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

  17. object Object extends Object

    The top-level Object JavaScript object.

  18. object RangeError extends Object

  19. object ReferenceError extends Object

  20. object RegExp extends Object

  21. object SyntaxError extends Object

  22. object ThisFunction

  23. object TypeError extends Object

  24. object URIError extends Object

  25. object URIUtils extends GlobalScope

    Methods related to URIs, provided by ECMAScript 5.1.

  26. object UndefOr

  27. object UndefOrOps

  28. object WrappedArray extends SeqFactory[WrappedArray]

    $factoryInfo

  29. object WrappedDictionary

  30. package annotation

  31. def debugger(): Unit

    Invokes any available debugging functionality.

    Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.

    MDN

    Browser support:

    • Has no effect in Rhino nor, apparently, in Firefox
    • In Chrome, it has no effect unless the developer tools are opened beforehand.
  32. def eval(x: String): Any

    Evaluates JavaScript code and returns the result.

    Evaluates JavaScript code and returns the result.

    Annotations
    @inline()
  33. def isUndefined(v: scala.Any): Boolean

    Tests whether the given value is undefined.

    Tests whether the given value is undefined.

    Annotations
    @inline()
  34. def native: Nothing

    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
    }
  35. package timers

    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).

  36. def typeOf(x: Any): String

    Returns the type of x as identified by typeof x in JavaScript.

  37. package typedarray

    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

  38. def undefined: UndefOr[Nothing]

    The undefined value.

    The undefined value.

    Annotations
    @inline()

Inherited from AnyRef

Inherited from scala.Any

Ungrouped