Package jsinterop.base
Class Js
java.lang.Object
jsinterop.base.Js
Utilities to provide access to JavaScript language constructs that are not available in pure
Java.
Note that this class avoids providing replacements for stuff that is already available via a pure Java or Elemental and enforce safe (runtime-checked) coding practices.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends @Nullable Object>
TandAlso
(T obj1, T obj2) Applies JavaScript logical "and" operator (&&
) on given objects.static JsArrayLike
<@Nullable Object> static @Nullable Any
static @Nullable Any[]
static @Nullable JsArrayLike
<@Nullable Object> asArrayLike
(@Nullable Object obj) ReturnsJsArrayLike
view of provided array-like object.static boolean
static byte
static char
static <T> JsConstructorFn
<T> asConstructorFn
(Class<T> clazz) static double
static float
static int
static long
static @Nullable JsPropertyMap
<@Nullable Object> asPropertyMap
(@Nullable Object obj) ReturnsJsPropertyMap
view of provided object.static short
static String
static <T extends @Nullable Object>
TPerforms checked cast to lefthand-side type.static boolean
coerceToBoolean
(@Nullable Object b) Coerces any object to boolean using!!
operation.static double
coerceToDouble
(@Nullable Object d) Coerces any object to number using+
operation.static int
coerceToInt
(@Nullable Object d) Coerces any object to 32 bit signed number using|0
operation.static void
debugger()
static JsPropertyMap
<@Nullable Object> global()
static boolean
static boolean
isTripleEqual
(@Nullable Object o1, @Nullable Object o2) Returnstrue
if two objects are same.static boolean
static <T extends @Nullable Object>
TorElse
(T obj1, T obj2) Applies JavaScript logical "or" operator (||
) on given objects.static String
static <T extends @Nullable Object>
TuncheckedCast
(@Nullable Object obj) Performs unchecked cast to lefthand-side type.static @Nullable Object
-
Method Details
-
undefined
-
arguments
@JsProperty(namespace="<window>", name="arguments") public static JsArrayLike<@Nullable Object> arguments() -
debugger
@JsProperty(namespace="<window>", name="debugger") public static void debugger() -
typeof
-
global
-
asConstructorFn
-
asAny
-
asPropertyMap
ReturnsJsPropertyMap
view of provided object. -
asArrayLike
ReturnsJsArrayLike
view of provided array-like object. -
asArray
-
asString
-
asBoolean
-
asDouble
-
asFloat
-
asLong
-
asInt
-
asShort
-
asChar
-
asByte
-
cast
Performs checked cast to lefthand-side type.This is useful for cases when Java won't allow you otherwise, like casting from a native interface to a final Java class (like String).
-
uncheckedCast
Performs unchecked cast to lefthand-side type.This method exists in order to lie to the type system, it is not an optimization. You should *ALWAYS* prefer regular casting over this which also optimizes for production. Using this method can leak incorrect types to the rest of the system which will result in hard to debug problems.
-
andAlso
Applies JavaScript logical "and" operator (&&
) on given objects. -
orElse
Applies JavaScript logical "or" operator (||
) on given objects. -
isTruthy
-
isFalsy
-
isTripleEqual
Returnstrue
if two objects are same.This method mostly behaves similar to Java
==
operator except that it doesn't returntrue
fornull==undefined
comparison. -
coerceToDouble
Coerces any object to number using+
operation. -
coerceToInt
Coerces any object to 32 bit signed number using|0
operation. -
coerceToBoolean
Coerces any object to boolean using!!
operation.
-