JavaScriptKit Documentation

Protocol JSBridged​Class

public protocol JSBridgedClass: JSBridgedType  

Conform to this protocol when your Swift class wraps a JavaScript class.

%87 JSBridgedClass JSBridgedClass JSBridgedType JSBridgedType JSBridgedClass->JSBridgedType JSDate JSDate JSDate->JSBridgedClass JSError JSError JSError->JSBridgedClass JSTypedArray JSTypedArray JSTypedArray->JSBridgedClass JSArray JSArray JSArray->JSBridgedClass JSPromise JSPromise JSPromise->JSBridgedClass

Conforms To

JSBridgedType

Use this protocol when your type has no single JavaScript class. For example, a union type of multiple classes or primitive values.

Types Conforming to JSBridged​Class

JSArray

A wrapper around the JavaScript Array class that exposes its properties in a type-safe and Swifty way.

JSDate

A wrapper around the JavaScript Date class that exposes its properties in a type-safe way. This doesn't 100% match the JS API, for example getMonth/setMonth etc accessor methods are converted to properties, but the rest of it matches in the naming. Parts of the JavaScript Date API that are not consistent across browsers and JS implementations are not exposed in a type-safe manner, you should access the underlying jsObject property if you need those.

JSError

A wrapper around the JavaScript Error class that exposes its properties in a type-safe way.

JSPromise

A wrapper around the JavaScript Promise class

JSTypedArray

A wrapper around all JavaScript TypedArray classes that exposes their properties in a type-safe way.

Default Implementations

js​Value

var jsValue: JSValue  

init?(from:​)

init?(from value: JSValue)  

init?(from:​)

init?(from object: JSObject)  

Requirements

constructor

static var constructor: JSFunction?  

The constructor function for the JavaScript class

js​Object

var jsObject: JSObject  

The JavaScript object wrapped by this instance. You may assume that jsObject instanceof Self.constructor == true

init(unsafely​Wrapping:​)

init(unsafelyWrapping jsObject: JSObject) 

Create an instance wrapping the given JavaScript object. You may assume that jsObject instanceof Self.constructor