Skip to content

Commit 9d4d950

Browse files
authored
Add void-returning overload to JSClosure.init (#34)
1 parent 5e79c1f commit 9d4d950

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/JavaScriptKit/JSFunction.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ public class JSClosure: JSFunctionRef {
8282
id = objectRef
8383
}
8484

85+
convenience public init(_ body: @escaping ([JSValue]) -> ()) {
86+
self.init { (arguments: [JSValue]) -> JSValue in
87+
body(arguments)
88+
return .undefined
89+
}
90+
}
91+
8592
public func release() {
8693
Self.sharedFunctions[hostFuncRef] = nil
8794
isReleased = true

0 commit comments

Comments
 (0)