@@ -35,9 +35,9 @@ public class JSObject: Equatable {
3535 /// - Parameter name: The name of this object's member to access.
3636 /// - Returns: The `name` member method binding this object as `this` context.
3737 @_disfavoredOverload
38- public subscript( _ name: String ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) ? {
38+ public subscript( _ name: String ) -> DiscardableResultClosure ? {
3939 guard let function = self [ name] . function else { return nil }
40- return { ( arguments: ConvertibleToJSValue ... ) in
40+ return DiscardableResultClosure { arguments in
4141 function ( this: self , arguments: arguments)
4242 }
4343 }
@@ -53,17 +53,17 @@ public class JSObject: Equatable {
5353 /// - Parameter name: The name of this object's member to access.
5454 /// - Returns: The `name` member method binding this object as `this` context.
5555 @_disfavoredOverload
56- public subscript( _ name: JSString ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) ? {
56+ public subscript( _ name: JSString ) -> DiscardableResultClosure ? {
5757 guard let function = self [ name] . function else { return nil }
58- return { ( arguments: ConvertibleToJSValue ... ) in
58+ return DiscardableResultClosure { arguments in
5959 function ( this: self , arguments: arguments)
6060 }
6161 }
6262
6363 /// A convenience method of `subscript(_ name: String) -> ((ConvertibleToJSValue...) -> JSValue)?`
6464 /// to access the member through Dynamic Member Lookup.
6565 @_disfavoredOverload
66- public subscript( dynamicMember name: String ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) ? {
66+ public subscript( dynamicMember name: String ) -> DiscardableResultClosure ? {
6767 self [ name]
6868 }
6969#endif
@@ -232,6 +232,19 @@ public class JSThrowingObject {
232232#endif
233233
234234
235+ #if !hasFeature(Embedded)
236+ /// A swift closure wrapper that can be called as function.
237+ /// This prevents the warnings for unused results through `@discardableResult` which means you no longer need `_ =` everywhere.
238+ public struct DiscardableResultClosure {
239+ var closure : ( [ ConvertibleToJSValue ] ) -> JSValue
240+
241+ @discardableResult
242+ public func callAsFunction( _ args: ConvertibleToJSValue ... ) -> JSValue {
243+ return self . closure ( args)
244+ }
245+ }
246+ #endif
247+
235248#if hasFeature(Embedded)
236249// NOTE: once embedded supports variadic generics, we can remove these overloads
237250public extension JSObject {
0 commit comments