Package kotlin.js

Platform and version requirements: JS

Functions and other APIs specific to the JavaScript platform.

Types

Console

external interface Console

Exposes the console API to Kotlin.

Date

external class Date

Exposes the Date API to Kotlin.

JSON

external object JSON

Exposes the JavaScript JSON object to Kotlin.

JsClass

external interface JsClass<T : Any>

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

Json

external interface 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?.

Math

external object Math

Exposes the JavaScript Math object to Kotlin.

Promise

open external class Promise<out T>

Exposes the JavaScript Promise object to Kotlin.

RegExp

external class RegExp

Exposes the JavaScript RegExp object to Kotlin.

RegExpMatch

external interface RegExpMatch

Represents the return value of RegExp.exec.

Annotations

JsModule

annotation class JsModule

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

JsName

annotation class JsName

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

JsNonModule

annotation class JsNonModule

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

JsQualifier

annotation class JsQualifier

Adds prefix to external declarations in a source file.

Properties

console

external val console: Console

Exposes the console API to Kotlin.

definedExternally

external val definedExternally: Nothing

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

js

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

Obtains a constructor reference for the given KClass.

kotlin

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

Obtains a KClass instance for the given constructor reference.

undefined

external val undefined: Nothing?

Exposes the JavaScript undefined property to Kotlin.

Functions

add

fun Json.add(other: Json): Json

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

asArray

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

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.

asDynamic

fun Any?.asDynamic(): dynamic

Reinterprets this value as a value of the dynamic type.

eval

external fun eval(expr: String): dynamic

Exposes the JavaScript eval function to Kotlin.

get

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

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.

iterator

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

Allows to iterate this dynamic object in the following cases:

js

external fun js(code: String): dynamic

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.

jsTypeOf

fun jsTypeOf(a: Any?): String

Function corresponding to JavaScript's typeof operator

json

fun json(vararg pairs: Pair<String, Any?>): Json

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

max

fun Math.max(a: Long, b: Long): Long

Returns the greater of two values.

min

fun Math.min(a: Long, b: Long): Long

Returns the smaller of two values.

reset

fun RegExp.reset()

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

unsafeCast

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

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