JsObject

open class JsObject

A JavaScript object seen from Kotlin. Reading and writing goes straight through to the engine, so a change here is a change the script sees.

Inheritors

Properties

Link copied to clipboard

The object's own enumerable string keys, in the order a script would see them.

Link copied to clipboard

The value this wrapper holds, for handing back to the engine.

Functions

Link copied to clipboard
fun JsObject.accessor(name: String, flags: PropertyFlags = PropertyFlags(), read: () -> Any?, write: (JsValue) -> Unit)

A property with both halves.

Link copied to clipboard
fun <T : Any> JsObject.bind(name: String, instance: T, build: BindScope<T>.() -> Unit): JsObject

Binds a Kotlin object into a fresh JavaScript object.

Link copied to clipboard
fun call(name: String, vararg args: Any?): JsValue

Calls a method on this object, the way obj.name(...) does in a script.

Link copied to clipboard
fun JsObject.constant(name: String, value: Any?)

Puts a value that a script can read but not change.

Link copied to clipboard
fun JsObject.constructor(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), build: (JsObject, List<JsValue>) -> Unit): JsFunction

A host constructor, callable with new. build fills in the object it is given.

Link copied to clipboard
fun delete(name: String)
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
inline fun <A, R> JsObject.function(name: String, crossinline body: (A) -> R): JsFunction

A one-argument host function, with the argument and the answer converted for you.

inline fun <A, B, R> JsObject.function(name: String, crossinline body: (A, B) -> R): JsFunction

A two-argument host function.

inline fun <A, B, C, R> JsObject.function(name: String, crossinline body: (A, B, C) -> R): JsFunction

A three-argument host function.

fun JsObject.function(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), body: (List<JsValue>) -> Any?): JsFunction

A host function that takes the arguments as they came.

Link copied to clipboard
operator fun get(index: Int): JsValue
operator fun get(name: String): JsValue
Link copied to clipboard
fun JsObject.getter(name: String, flags: PropertyFlags = PropertyFlags(), read: () -> Any?)

A property computed on every read.

Link copied to clipboard
fun has(name: String): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun JsObject.method(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), body: (self: JsValue, args: List<JsValue>) -> Any?): JsFunction

A host function that also wants the this it was called on.

Link copied to clipboard
fun JsObject.obj(name: String, build: JsObject.() -> Unit = {}): JsObject

A nested object, built by build. Returns it so you can keep a handle.

Link copied to clipboard
fun JsObject.property(name: String, value: Any?, flags: PropertyFlags = PropertyFlags())

Puts a value on the object.

Link copied to clipboard
operator fun set(index: Int, value: Any?)
operator fun set(name: String, value: Any?)
Link copied to clipboard
fun JsObject.setter(name: String, flags: PropertyFlags = PropertyFlags(), write: (JsValue) -> Unit)

A property that only accepts writes.

Link copied to clipboard
fun toMap(): Map<String, Any?>

A plain Kotlin map, all the way down. Cycles come back as the JsObject that closed them.

Link copied to clipboard
open override fun toString(): String