JSObjectUnsafeUtilExtension
LogoDart

JSObjectUnsafeUtilExtension#

extension JSObjectUnsafeUtilExtension on JSObject

Utility methods to check, get, set, and call properties on a JSObject.

See the JavaScript specification for more details on using properties.

Methods#

callMethod() extension#

R callMethod<R extends JSAny?>( JSAny method, [ JSAny? arg1, JSAny? arg2, JSAny? arg3, JSAny? arg4, ]);

Calls method on this JSObject with up to four arguments.

Returns the result of calling method, 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 callMethodVarArgs if you need to pass nulls.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
R callMethod<R extends JSAny?>(
  JSAny method, [
  JSAny? arg1,
  JSAny? arg2,
  JSAny? arg3,
  JSAny? arg4,
]) => _callMethod(method, arg1, arg2, arg3, arg4) as R;

callMethodVarArgs() extension#

R callMethodVarArgs<R extends JSAny?>( JSAny method, [ List<JSAny?>? arguments, ]);

Calls method on this JSObject with a variable number of arguments.

Returns the result of calling method, which must be an R.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
R callMethodVarArgs<R extends JSAny?>(
  JSAny method, [
  List<JSAny?>? arguments,
]) => _callMethodVarArgs(method, arguments) as R;

delete() extension#

JSBoolean delete(JSAny property)

Deletes the property with key property from this JSObject.

Uses JavaScript's delete to delete the property.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
external JSBoolean delete(JSAny property);

getProperty() extension#

R getProperty<R extends JSAny?>(JSAny property)

The value of the property key property of this JSObject.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
external R getProperty<R extends JSAny?>(JSAny property);

has() extension#

bool has(String property)

Shorthand helper for hasProperty to check whether this JSObject contains the property key property, but takes and returns a Dart value.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
bool has(String property) => hasProperty(property.toJS).toDart;

hasProperty() extension#

JSBoolean hasProperty(JSAny property)

Whether or not this JSObject contains the property key property.

Uses JavaScript's in to check.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
external JSBoolean hasProperty(JSAny property);

setProperty() extension#

void setProperty(JSAny property, JSAny? value)

Write the value of property key property of this JSObject.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
external void setProperty(JSAny property, JSAny? value);

Operators#

operator []() extension#

JSAny? operator [](String property)

Shorthand helper for getProperty to get the value of the property key property of this JSObject, but takes a Dart value.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
JSAny? operator [](String property) => getProperty(property.toJS);

operator []=() extension#

void operator []=(String property, JSAny? value)

Shorthand helper for setProperty to write the value of the property key property of this JSObject, but takes a Dart value.

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Implementation
void operator []=(String property, JSAny? value) =>
    setProperty(property.toJS, value);