dart:js_util library
Utility methods to manipulatepackage:js annotated JavaScript interopobjects in cases where the name to call is not known at runtime.
Note
You should usually usedart:js_interop instead of this library.To learn more, check out theJS interop documentation.
You should only use these methods when the same effect cannot be achievedwith@JS() annotations.
Properties
- globalThis→Object
- no setter
- objectPrototype→Object?
- Returns the
Objectprototype. Equivalent toObject.prototype.no setter
Functions
- add<
T> (Object?first,Object?second)→ T - Perform JavaScript addition (
+) on two values. - allowInterop<
F extendsFunction> (Ff)→ F - Returns a wrapper around function
fthat can be called from JavaScriptusingpackage:jsJavaScript interop. - allowInteropCaptureThis(
Functionf)→Function - Returns a wrapper around function
fthat can be called from JavaScriptusingpackage:jsJavaScript interop, passing JavaScriptthisas thefirst argument. - and<
T> (Object?first,Object?second)→ T - Perform JavaScript logical and comparison (
&&) of two expressions. - callConstructor<
T> (Objectconstr,List< Object?> ?arguments)→ T - callMethod<
T> (Objecto,Objectmethod,List< Object?> args)→ T - createDartExport<
T extendsObject> (TdartObject)→Object - Given a Dart object that is marked exportable, creates a JS object literalthat forwards to that Dart class. Look at the
@JSExportannotation todetermine what constitutes "exportable" for a Dart class. The object literalwill be a map of export names (which are either the written instance membernames or their rename) to their respective Dart instance members. - createStaticInteropMock<
T extendsObject,U extendsObject> (UdartMock, [Object?proto =null])→ T - Given a
@staticInteroptype T and an instancedartMockof a Dart classU that implements the external extension members of T, creates a forwardingmock. - dartify(
Object?o)→Object? - Effectively the inverse ofjsify,dartify Takes a JavaScript object, andconverts it to a Dart based object. Only JS primitives, arrays, or 'map'like JS objects are supported.
- delete<
T> (Objecto,Objectproperty)→bool - Perform JavaScript delete operator (
delete) on the given property of thegiven object. - divide<
T> (Object?first,Object?second)→ T - Perform JavaScript division (
/) on two values. - equal<
T> (Object?first,Object?second)→bool - Perform JavaScript equality comparison (
==) on two values. - exponentiate<
T> (Object?first,Object?second)→ T - Perform JavaScript exponentiation (
**) on two values. - getProperty<
T> (Objecto,Objectname)→ T - greaterThan<
T> (Object?first,Object?second)→bool - Perform JavaScript greater than comparison (
>) of two values. - greaterThanOrEqual<
T> (Object?first,Object?second)→bool - Perform JavaScript greater than or equal comparison (
>=) of two values. - hasProperty(
Objecto,Objectname)→bool - instanceof(
Object?o,Objecttype)→bool - Check whether
ois an instance oftype. - instanceOfString(
Object?element,StringobjectType)→bool - Likeinstanceof only takes aString for the object name instead of aconstructor object.
- isJavaScriptArray(
dynamicvalue)→bool - Returns
trueif a given object is a JavaScript array. - isJavaScriptSimpleObject(
dynamicvalue)→bool - Returns
trueif a given object is a simple JavaScript object. - isTruthy<
T> (Object?o)→bool - Determines if the given object is truthy or falsy.
- jsify(
Object?object)→ dynamic - Recursively converts a JSON-like collection to JavaScript compatiblerepresentation.
- lessThan<
T> (Object?first,Object?second)→bool - Perform JavaScript less than comparison (
<) of two values. - lessThanOrEqual<
T> (Object?first,Object?second)→bool - Perform JavaScript less than or equal comparison (
<=) of two values. - modulo<
T> (Object?first,Object?second)→ T - Perform JavaScript remainder (
%) on two values. - multiply<
T> (Object?first,Object?second)→ T - Perform JavaScript multiplication (
*) on two values. - newObject<
T> ()→ T - not<
T> (Object?o)→ T - Perform JavaScript logical not (
!) on the given object. - notEqual<
T> (Object?first,Object?second)→bool - Perform JavaScript inequality comparison (
!=) on two values. - objectGetPrototypeOf(
Object?object)→Object? - Returns the prototype of a given object. Equivalent to
Object.getPrototypeOf. - objectKeys(
Object?object)→List< Object?> - Returns the keys for a given object. Equivalent to
Object.keys(object). - or<
T> (Object?first,Object?second)→ T - Perform JavaScript logical or comparison (
||) of two expressions. - promiseToFuture<
T> (ObjectjsPromise)→Future< T> - Converts a JavaScript Promise to a DartFuture.
- setProperty<
T> (Objecto,Objectname,T?value)→ T - strictEqual<
T> (Object?first,Object?second)→bool - Perform JavaScript strict equality comparison (
===) on two values. - strictNotEqual<
T> (Object?first,Object?second)→bool - Perform JavaScript strict inequality comparison (
!==) on two values. - subtract<
T> (Object?first,Object?second)→ T - Perform JavaScript subtraction (
-) on two values. - typeofEquals<
T> (Object?o,Stringtype)→bool - Perform JavaScript
typeofoperator on the given object and determine ifthe result is equal to the given type. Exposes the wholetypeofequalexpression to maximize browser optimization. - unsignedRightShift(
Object?leftOperand,Object?rightOperand)→num - Perform JavaScript unsigned right shift operator (
>>>) on the given leftoperand by the amount specified by the given right operand.
Exceptions / Errors
- NullRejectionException
- Exception for when aJSPromise that is converted viaJSPromiseToFuture.toDart is rejected with a
nullorundefinedvalue.