Skip to content

JSFunctionUnsafeUtilExtension

extension JSFunctionUnsafeUtilExtension on JSFunction

Utility methods to call JSFunctions as constructors.

Methods

callAsConstructor() extension

R callAsConstructor<R>([JSAny? arg1, JSAny? arg2, JSAny? arg3, JSAny? arg4])

Calls this JSFunction as a constructor with up to four arguments.

Returns the constructed object, which must be an R.

This helper doesn't allow passing nulls, as it determines whether an argument is passed based on whether it was null or not. Prefer callAsConstructorVarArgs if you need to pass nulls.

Available on JSFunction, provided by the JSFunctionUnsafeUtilExtension extension

Implementation
dart
&#47;&#47; TODO(srujzs): The type bound should extend `JSObject`.
R callAsConstructor<R>([
  JSAny? arg1,
  JSAny? arg2,
  JSAny? arg3,
  JSAny? arg4,
]) => _callAsConstructor(arg1, arg2, arg3, arg4) as R;

callAsConstructorVarArgs() extension

R callAsConstructorVarArgs<R extends JSObject>([List<JSAny?>? arguments])

Calls this JSFunction as a constructor with a variable number of arguments.

Returns the constructed JSObject, which must be an R.

Available on JSFunction, provided by the JSFunctionUnsafeUtilExtension extension

Implementation
dart
R callAsConstructorVarArgs<R extends JSObject>([List<JSAny?>? arguments]) =>
    _callAsConstructorVarArgs(arguments) as R;