Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aed4312

Browse files
Add compatibility method for JSValue.function(_:JSClosure)
1 parent 110b72d commit aed4312

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Example/JavaScriptKitExample/Sources/JavaScriptKitExample/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ buttonElement.innerText = "Click me!"
1212
let listener = JSClosure { _ in
1313
alert("Swift is running on browser!")
1414
}
15-
buttonElement.onclick = .function(listener)
15+
buttonElement.onclick = .object(listener)
1616

1717
_ = document.body.appendChild(buttonElement)

Sources/JavaScriptKit/JSValue.swift

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ extension JSValue {
144144
public static func function(_ body: @escaping ([JSValue]) -> JSValue) -> JSValue {
145145
.object(JSClosure(body))
146146
}
147+
148+
@available(*, deprecated, renamed: "object", message: "JSClosure is not a subclass of JSFunction now")
149+
public static func function(_ closure: JSClosure) -> JSValue {
150+
.object(closure)
151+
}
147152
}
148153

149154
extension JSValue: ExpressibleByStringLiteral {

0 commit comments

Comments
 (0)