JavaScriptKit Documentation

Class JSClosure

public class JSClosure: JSObject, JSClosureProtocol  

JSClosure represents a JavaScript function the body of which is written in Swift. This type can be passed as a callback handler to JavaScript functions.

e.g.

let eventListenter = JSClosure { _ in
    ...
    return JSValue.undefined
}

button.addEventListener!("click", JSValue.function(eventListenter))
...
button.removeEventListener!("click", JSValue.function(eventListenter))
%51 JSClosure JSClosure JSClosureProtocol JSClosureProtocol JSClosure->JSClosureProtocol JSObject JSObject JSClosure->JSObject

Superclass

JSObject

JSObject represents an object in JavaScript and supports dynamic member lookup. Any member access like object.foo will dynamically request the JavaScript and Swift runtime bridge library for a member with the specified name in this object.

Conforms To

JSClosureProtocol

JSClosureProtocol wraps Swift closure objects for use in JavaScript. Conforming types are responsible for managing the lifetime of the closure they wrap, but can delegate that task to the user by requiring an explicit release() call.

Initializers

init(_:​)

@available(*, deprecated, message: "This initializer will be removed in the next minor version update. Please use `init(_ body: @escaping ([JSValue]) -> JSValue)` and add `return .undefined` to the end of your closure")
    @_disfavoredOverload
    public convenience init(_ body: @escaping ([JSValue]) -> ())  

init(_:​file:​line:​)

public init(_ body: @escaping ([JSValue]) -> JSValue, file: String = #fileID, line: UInt32 = #line)  

Methods

release()

public func release()  

release()

@available(*, deprecated, message: "JSClosure.release() is no longer necessary")
    public func release()