Package kotlin.js

Functions and other APIs specific to the JavaScript platform.

Types

JS
1.1

Console

Exposes the console API to Kotlin.

interface Console
JS
1.1

Date

Exposes the Date API to Kotlin.

class Date
JS
1.1

JsClass

Represents the constructor of a class. Instances of JsClass can be passed to JavaScript APIs that expect a constructor reference.

interface JsClass<T : Any>
JS
1.1

Json

An interface for indexing access to a collection of key-value pairs, where type of key is String and type of value is Any?.

interface Json
JS
1.1

JSON

Exposes the JavaScript JSON object to Kotlin.

object JSON
JS
1.1

Promise

Exposes the JavaScript Promise object to Kotlin.

open class Promise<out T>
JS
1.1

RegExp

Exposes the JavaScript RegExp object to Kotlin.

class RegExp
JS
1.1

RegExpMatch

Represents the return value of RegExp.exec.

interface RegExpMatch

Annotations

JS
1.6

EagerInitialization

Forces a top-level property to be initialized eagerly, opposed to lazily on the first access to file and/or property.

annotation class EagerInitialization
Common
JVM
JS
Native
2.0

ExperimentalJsCollectionsApi

This annotation marks the experimental JS-collections API that allows to manipulate with native JS-collections The API can be removed completely in any further release.

annotation class ExperimentalJsCollectionsApi
Common
JVM
JS
Native
1.4

ExperimentalJsExport

Marks experimental JS export annotations.

annotation class ExperimentalJsExport
Common
JVM
JS
Native
1.9

ExperimentalJsFileName

Marks experimental JsFileName annotation.

annotation class ExperimentalJsFileName
Common
JVM
JS
Native
1.9

ExperimentalJsReflectionCreateInstance

This annotation marks the experimental Kotlin/JS reflection API that allows to create an instance of provided KClass The API can be removed completely in any further release.

annotation class ExperimentalJsReflectionCreateInstance
Common
JVM
JS
Native
2.0

ExperimentalJsStatic

Marks the experimental JsStatic annotation.

annotation class ExperimentalJsStatic
Common
JS
1.3

JsExport

Exports top-level declaration on JS platform.

annotation class JsExport
JS
1.9

JsExternalArgument

When placed on a function parameter, requires the type of the passed argument to be external.

annotation class JsExternalArgument
JS
1.9

JsExternalInheritorsOnly

When placed on an external interface or class, requires all its child interfaces, classes, and objects to be external as well.

annotation class JsExternalInheritorsOnly
Common
JS
1.9

JsFileName

Specifies the name of the compiled file produced from the annotated source file instead of the default one.

annotation class JsFileName
JS
1.1

JsModule

Denotes an external declaration that must be imported from native JavaScript library.

annotation class JsModule
Common
JS
1.0

JsName

Gives a declaration (a function, a property or a class) specific name in JavaScript.

annotation class JsName
JS
1.1

JsNonModule

Denotes an external declaration that can be used without module system.

annotation class JsNonModule
JS
1.1

JsQualifier

Adds prefix to external declarations in a source file.

annotation class JsQualifier
Common
JS
2.0

JsStatic

Specifies that an additional static method is generated from the annotated companion object member if it's a function. If the member is a property, additional static getter/setter methods are generated.

annotation class JsStatic
JS
1.1

nativeGetter

annotation class nativeGetter
JS
1.1

nativeInvoke

annotation class nativeInvoke
JS
1.1

nativeSetter

annotation class nativeSetter

Properties

JS
1.1

console

Exposes the console API to Kotlin.

val console: Console
JS
1.1

definedExternally

The property that can be used as a placeholder for statements and values that are defined in JavaScript.

val definedExternally: Nothing
JS
1.1

js

Obtains a constructor reference for the given KClass.

val <T : Any> KClass<T>.js: JsClass<T>
JS
1.1

kotlin

Obtains a KClass instance for the given constructor reference.

val <T : Any> JsClass<T>.kotlin: KClass<T>
JS
1.1

noImpl

val noImpl: Nothing
JS
1.1

undefined

Exposes the JavaScript undefined property to Kotlin.

val undefined: Nothing?

Functions

JS
1.1

add

Adds key-value pairs from other to this. Returns the original receiver.

fun Json.add(other: Json): Json
JS
1.1

asArray

Converts the result of RegExp.exec to an array where the first element contains the entire matched text and each subsequent element is the text matched by each capturing parenthesis.

fun RegExpMatch.asArray(): Array<out String?>
JS
1.1

asDynamic

Reinterprets this value as a value of the dynamic type.

fun Any?.asDynamic(): dynamic
JS
1.1

dateLocaleOptions

fun dateLocaleOptions(
    init: LocaleOptions.() -> Unit
): LocaleOptions
JS
1.1

eval

Exposes the JavaScript eval function to Kotlin.

fun eval(expr: String): dynamic
JS
1.1

get

Returns the entire text matched by RegExp.exec if the index parameter is 0, or the text matched by the capturing parenthesis at the given index.

operator fun RegExpMatch.get(index: Int): String?
JS
1.1

iterator

Allows to iterate this dynamic object in the following cases:

operator fun dynamic.iterator(): Iterator<dynamic>
JS
1.1

js

Puts the given piece of a JavaScript code right into the calling function. The compiler replaces call to js(...) code with the string constant provided as a parameter.

fun js(code: String): dynamic
JS
1.1

json

Returns a simple JavaScript object (as Json) using provided key-value pairs as names and values of its properties.

fun json(vararg pairs: <ERROR CLASS><String, Any?>): Json
JS
1.1

jsTypeOf

Function corresponding to JavaScript's typeof operator

fun jsTypeOf(a: Any?): String
JS
1.1

parseFloat

fun parseFloat(
    s: String,
    radix: Int = definedExternally
): Double
JS
1.1

parseInt

fun parseInt(s: String): Int
fun parseInt(s: String, radix: Int = definedExternally): Int
JS
1.1

reset

Resets the regular expression so that subsequent RegExp.test and RegExp.exec calls will match starting with the beginning of the input string.

fun RegExp.reset()
JS
1.1

then

fun <T, S> Promise<Promise<T>>.then(
    onFulfilled: ((T) -> S)?
): Promise<S>
fun <T, S> Promise<Promise<T>>.then(
    onFulfilled: ((T) -> S)?,
    onRejected: ((Throwable) -> S)?
): Promise<S>
JS
1.1

unsafeCast

Reinterprets this value as a value of the specified type T without any actual type checking.

fun <T> Any?.unsafeCast(): T

Reinterprets this dynamic value as a value of the specified type T without any actual type checking.

fun <T> dynamic.unsafeCast(): T