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 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:

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.

A | B is an unboxed pseudo-union type, suitable to type values that admit several unrelated types in facade types.

Linear Supertypes
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

    Root of the hierarchy of JavaScript types.

  2. class Array[A] extends Object

    Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations.

  3. final class ArrayOps[A] extends ArrayLike[A, Array[A]] with Builder[A, Array[A]]

    Equivalent of scm.

  4. final class ConstructorTag[T <: Any] extends AnyVal

    Stores the JS constructor function of a JS class.

  5. class Date extends Object

    Creates a JavaScript Date instance that represents a single moment in time.

  6. sealed trait Dictionary[A] extends Any

    Dictionary "view" of a JavaScript value.

  7. sealed trait Dynamic extends Any with scala.Dynamic

    Dynamically typed JavaScript value.

  8. class Error extends Object

    Annotations
    @RawJSType() @native()
  9. class EvalError extends Error

    An instance representing an error that occurs regarding the global function eval()

  10. class Function extends Object

    The Function constructor creates a new Function object.

  11. trait Function0[+R] extends Function

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

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

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

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

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

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

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

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

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

    Annotations
    @RawJSType() @native()
  21. 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() @native()
  22. 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() @native()
  23. trait Function2[-T1, -T2, +R] extends Function

    Annotations
    @RawJSType() @native()
  24. 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() @native()
  25. 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() @native()
  26. 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() @native()
  27. trait Function3[-T1, -T2, -T3, +R] extends Function

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

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

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

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

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

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

    Annotations
    @RawJSType() @native()
  34. trait GlobalScope extends Any

    Marker trait for top-level objects representing the JS global scope.

  35. trait JSApp extends AnyRef

    Base class for top-level, entry point main objects.

  36. trait JSArrayOps[A] extends Object

    Discouraged native JavaScript Array methods.

  37. sealed abstract class JSConvertersLowPrioImplicits extends AnyRef

  38. trait JSNumberOps extends Any

    Operations on JavaScript numbers.

  39. trait JSStringOps extends Any

    Operations on JavaScript strings.

  40. case class JavaScriptException(exception: scala.Any) extends RuntimeException with Product with Serializable

  41. trait LowPrioAnyImplicits extends AnyRef

  42. class Object extends Any

    Base class of all JavaScript objects.

  43. class Promise[+A] extends Object with Thenable[A]

    ECMAScript 6 Promise of an asynchronous result.

  44. trait PropertyDescriptor extends Object

    Annotations
    @RawJSType() @native()
  45. class RangeError extends Error

    An instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.

  46. class ReferenceError extends Error

    Represents an error when a non-existent variable is referenced.

  47. class RegExp extends Object

    The RegExp constructor creates a regular expression object for matching text with a pattern.

  48. class SyntaxError extends Error

    Represents an error when trying to interpret syntactically invalid code.

  49. trait Thenable[+A] extends Object

    A thing on which one can call the then method.

  50. trait ThisFunction extends Function

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

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

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

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

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

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

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

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

    Annotations
    @RawJSType() @native()
  58. 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() @native()
  59. 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() @native()
  60. 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() @native()
  61. 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() @native()
  62. 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() @native()
  63. trait ThisFunction2[-T0, -T1, -T2, +R] extends Function with ThisFunction

    Annotations
    @RawJSType() @native()
  64. 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() @native()
  65. 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() @native()
  66. trait ThisFunction3[-T0, -T1, -T2, -T3, +R] extends Function with ThisFunction

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

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

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

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

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

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

    Annotations
    @RawJSType() @native()
  73. sealed trait Tuple10[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10] extends Object

    A tuple "view" of 10 elements of a JavaScript Array.

  74. sealed trait Tuple11[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11] extends Object

    A tuple "view" of 11 elements of a JavaScript Array.

  75. sealed trait Tuple12[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12] extends Object

    A tuple "view" of 12 elements of a JavaScript Array.

  76. sealed trait Tuple13[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13] extends Object

    A tuple "view" of 13 elements of a JavaScript Array.

  77. sealed trait Tuple14[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14] extends Object

    A tuple "view" of 14 elements of a JavaScript Array.

  78. sealed trait Tuple15[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15] extends Object

    A tuple "view" of 15 elements of a JavaScript Array.

  79. sealed trait Tuple16[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16] extends Object

    A tuple "view" of 16 elements of a JavaScript Array.

  80. sealed trait Tuple17[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17] extends Object

    A tuple "view" of 17 elements of a JavaScript Array.

  81. sealed trait Tuple18[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18] extends Object

    A tuple "view" of 18 elements of a JavaScript Array.

  82. sealed trait Tuple19[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19] extends Object

    A tuple "view" of 19 elements of a JavaScript Array.

  83. sealed trait Tuple2[+T1, +T2] extends Object

    A tuple "view" of 2 elements of a JavaScript Array.

  84. sealed trait Tuple20[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19, +T20] extends Object

    A tuple "view" of 20 elements of a JavaScript Array.

  85. sealed trait Tuple21[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19, +T20, +T21] extends Object

    A tuple "view" of 21 elements of a JavaScript Array.

  86. sealed trait Tuple22[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19, +T20, +T21, +T22] extends Object

    A tuple "view" of 22 elements of a JavaScript Array.

  87. sealed trait Tuple3[+T1, +T2, +T3] extends Object

    A tuple "view" of 3 elements of a JavaScript Array.

  88. sealed trait Tuple4[+T1, +T2, +T3, +T4] extends Object

    A tuple "view" of 4 elements of a JavaScript Array.

  89. sealed trait Tuple5[+T1, +T2, +T3, +T4, +T5] extends Object

    A tuple "view" of 5 elements of a JavaScript Array.

  90. sealed trait Tuple6[+T1, +T2, +T3, +T4, +T5, +T6] extends Object

    A tuple "view" of 6 elements of a JavaScript Array.

  91. sealed trait Tuple7[+T1, +T2, +T3, +T4, +T5, +T6, +T7] extends Object

    A tuple "view" of 7 elements of a JavaScript Array.

  92. sealed trait Tuple8[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] extends Object

    A tuple "view" of 8 elements of a JavaScript Array.

  93. sealed trait Tuple9[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] extends Object

    A tuple "view" of 9 elements of a JavaScript Array.

  94. class TypeError extends Error

    Represents an error when a value is not of the expected type.

  95. class URIError extends Error

    Represents an error when a malformed URI is encountered.

  96. sealed trait UndefOr[+A] extends AnyRef

    Value of type A or the JS undefined value.

  97. sealed abstract class UndefOrLowPrioImplicits extends AnyRef

  98. final class UndefOrOps[A] extends AnyVal

  99. sealed trait UnicodeNormalizationForm extends Any

    A Unicode Normalization Form.

  100. final class Using[A] extends AnyVal

    Helper for syntactic sugar of js.use.

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

  102. class WrappedDictionary[A] extends AbstractMap[String, A] with Map[String, A] with MapLike[String, A, WrappedDictionary[A]]

    Wrapper to use a js.

  103. class native extends Annotation with StaticAnnotation

    Marks the annotated class, trait or object as a native JS entity.

  104. sealed trait |[A, B] extends AnyRef

    Value of type A or B (union type).

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 ConstructorTag

  5. object Date extends Object

    Factory for js.Date objects.

  6. object Dictionary

    Factory for Dictionary instances.

  7. object Dynamic

    Factory for dynamically typed JavaScript values.

  8. object DynamicImplicits

    Provides implicit conversions and operations to write in JavaScript style with js.Dynamic.

  9. object Error extends Object

    Annotations
    @native()
  10. object EvalError extends Object

    Annotations
    @native()
  11. object Function extends Object

    Annotations
    @native()
  12. object JSArrayOps

  13. object JSConverters extends JSConvertersLowPrioImplicits

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

  14. object JSNumberOps

  15. object JSON extends Object

    The JSON object contains methods for converting values to JavaScript Object Notation (JSON) and for converting JSON to values.

  16. object JSStringOps

  17. object Math extends Object

    Math is a built-in object that has properties and methods for mathematical constants and functions.

  18. object Object extends Object

    The top-level Object JavaScript object.

  19. object Promise extends Object

    Annotations
    @native()
  20. object RangeError extends Object

    Annotations
    @native()
  21. object ReferenceError extends Object

    Annotations
    @native()
  22. object RegExp extends Object

    Annotations
    @native()
  23. object SyntaxError extends Object

    Annotations
    @native()
  24. object Thenable

  25. object ThisFunction

  26. object Tuple10

  27. object Tuple11

  28. object Tuple12

  29. object Tuple13

  30. object Tuple14

  31. object Tuple15

  32. object Tuple16

  33. object Tuple17

  34. object Tuple18

  35. object Tuple19

  36. object Tuple2

  37. object Tuple20

  38. object Tuple21

  39. object Tuple22

  40. object Tuple3

  41. object Tuple4

  42. object Tuple5

  43. object Tuple6

  44. object Tuple7

  45. object Tuple8

  46. object Tuple9

  47. object TypeError extends Object

    Annotations
    @native()
  48. object URIError extends Object

    Annotations
    @native()
  49. object URIUtils extends GlobalScope

    Methods related to URIs, provided by ECMAScript 5.

  50. object UndefOr extends UndefOrLowPrioImplicits

  51. object UndefOrOps

  52. object UnicodeNormalizationForm

  53. object WrappedArray extends SeqFactory[WrappedArray]

    Factory for WrappedArray.

  54. object WrappedDictionary

  55. package annotation

  56. def constructorOf[T <: Any]: Dynamic

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

  57. def constructorTag[T <: Any](implicit tag: ConstructorTag[T]): ConstructorTag[T]

    Makes explicit an implicitly available ConstructorTag[T].

  58. 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.
  59. def eval(x: String): Any

    Evaluates JavaScript code and returns the result.

    Evaluates JavaScript code and returns the result.

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

    Tests whether the given value is undefined.

    Tests whether the given value is undefined.

    Annotations
    @inline()
  61. 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
    }
  62. package timers

    Non-Standard Non-standard, but in general well supported methods to schedule asynchronous exeuction.

  63. def typeOf(x: Any): String

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

  64. package typedarray

    ECMAScript 6 The typdearray package provides facade types for JavaScript ArrayBuffer, TypeArrays and DataView.

  65. def undefined: UndefOr[Nothing]

    The undefined value.

    The undefined value.

    Annotations
    @inline()
  66. def use[A](x: A): Using[A]

    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.

    Examples

    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

    Restrictions

    • Facade types may only be traits and not have any class ancestors
    • Polymorphic methods are currently not supported
    • Facade types defining an apply method cannot used (this is a JavaScript restriction).
  67. object |

Inherited from AnyRef

Inherited from scala.Any

Ungrouped