Skip to content

dart:js_util

Utility methods to manipulate package:js annotated JavaScript interop objects in cases where the name to call is not known at runtime.

INFO

You should usually use dart:js_interop instead of this library. To learn more, check out the JS interop documentation.

You should only use these methods when the same effect cannot be achieved with @JS() annotations.

Exceptions

ExceptionDescription
NullRejectionExceptionException for when a JSPromise that is converted via JSPromiseToFuture.toDart is rejected with a null or undefined value.

Functions

FunctionDescription
add<T>Perform JavaScript addition (+) on two values.
allowInterop<F extends Function>Returns a wrapper around function f that can be called from JavaScript using package:js JavaScript interop.
allowInteropCaptureThisReturns a wrapper around function f that can be called from JavaScript using package:js JavaScript interop, passing JavaScript this as the first argument.
and<T>Perform JavaScript logical and comparison (&&) of two expressions.
callConstructor<T>
callMethod<T>
createDartExport<T extends Object>Given a Dart object that is marked exportable, creates a JS object literal that forwards to that Dart class. Look at the @JSExport annotation to determine what constitutes "exportable" for a Dart class. The object literal will be a map of export names (which are either the written instance member names or their rename) to their respective Dart instance members.
createStaticInteropMock<T extends Object, U extends Object>Given a @staticInterop type T and an instance dartMock of a Dart class U that implements the external extension members of T, creates a forwarding mock.
dartifyEffectively the inverse of jsify, dartify Takes a JavaScript object, and converts it to a Dart based object. Only JS primitives, arrays, or 'map' like JS objects are supported.
delete<T>Perform JavaScript delete operator (delete) on the given property of the given object.
divide<T>Perform JavaScript division (/) on two values.
equal<T>Perform JavaScript equality comparison (==) on two values.
exponentiate<T>Perform JavaScript exponentiation (**) on two values.
getProperty<T>
greaterThan<T>Perform JavaScript greater than comparison (>) of two values.
greaterThanOrEqual<T>Perform JavaScript greater than or equal comparison (>=) of two values.
hasProperty
instanceofCheck whether o is an instance of type.
instanceOfStringLike instanceof only takes a String for the object name instead of a constructor object.
isJavaScriptArrayReturns true if a given object is a JavaScript array.
isJavaScriptSimpleObjectReturns true if a given object is a simple JavaScript object.
isTruthy<T>Determines if the given object is truthy or falsy.
jsifyRecursively converts a JSON-like collection to JavaScript compatible representation.
lessThan<T>Perform JavaScript less than comparison (<) of two values.
lessThanOrEqual<T>Perform JavaScript less than or equal comparison (<=) of two values.
modulo<T>Perform JavaScript remainder (%) on two values.
multiply<T>Perform JavaScript multiplication (*) on two values.
newObject<T>
not<T>Perform JavaScript logical not (!) on the given object.
notEqual<T>Perform JavaScript inequality comparison (!=) on two values.
objectGetPrototypeOfReturns the prototype of a given object. Equivalent to Object.getPrototypeOf.
objectKeysReturns the keys for a given object. Equivalent to Object.keys(object).
or<T>Perform JavaScript logical or comparison (||) of two expressions.
promiseToFuture<T>Converts a JavaScript Promise to a Dart Future.
setProperty<T>
strictEqual<T>Perform JavaScript strict equality comparison (===) on two values.
strictNotEqual<T>Perform JavaScript strict inequality comparison (!==) on two values.
subtract<T>Perform JavaScript subtraction (-) on two values.
typeofEquals<T>Perform JavaScript typeof operator on the given object and determine if the result is equal to the given type. Exposes the whole typeof equal expression to maximize browser optimization.
unsignedRightShiftPerform JavaScript unsigned right shift operator (>>>) on the given left operand by the amount specified by the given right operand.

Properties

PropertyDescription
globalThis
objectPrototypeReturns the Object prototype. Equivalent to Object.prototype.