Class Js

java.lang.Object
jsinterop.base.Js

public final class Js extends Object
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 Details

    • undefined

      @JsProperty(namespace="<window>", name="undefined") public static @Nullable Object undefined()
    • arguments

      @JsProperty(namespace="<window>", name="arguments") public static JsArrayLike<@Nullable Object> arguments()
    • debugger

      @JsProperty(namespace="<window>", name="debugger") public static void debugger()
    • typeof

      @JsMethod(namespace="<window>") public static String typeof(@Nullable Object obj)
    • global

      public static JsPropertyMap<@Nullable Object> global()
    • asConstructorFn

      public static <T> JsConstructorFn<T> asConstructorFn(Class<T> clazz)
    • asAny

      public static @Nullable Any asAny(@Nullable Object obj)
    • asPropertyMap

      public static @Nullable JsPropertyMap<@Nullable Object> asPropertyMap(@Nullable Object obj)
      Returns JsPropertyMap view of provided object.
    • asArrayLike

      public static @Nullable JsArrayLike<@Nullable Object> asArrayLike(@Nullable Object obj)
      Returns JsArrayLike view of provided array-like object.
    • asArray

      public static @Nullable Any[] asArray(Object obj)
    • asString

      public static String asString(Object obj)
    • asBoolean

      public static boolean asBoolean(Object obj)
    • asDouble

      public static double asDouble(Object obj)
    • asFloat

      public static float asFloat(Object obj)
    • asLong

      public static long asLong(Object obj)
    • asInt

      public static int asInt(Object obj)
    • asShort

      public static short asShort(Object obj)
    • asChar

      public static char asChar(Object obj)
    • asByte

      public static byte asByte(Object obj)
    • cast

      public static <T extends @Nullable Object> T cast(@Nullable Object obj)
      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

      public static <T extends @Nullable Object> T uncheckedCast(@Nullable Object obj)
      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

      public static <T extends @Nullable Object> T andAlso(T obj1, T obj2)
      Applies JavaScript logical "and" operator (&&) on given objects.
    • orElse

      public static <T extends @Nullable Object> T orElse(T obj1, T obj2)
      Applies JavaScript logical "or" operator (||) on given objects.
    • isTruthy

      public static boolean isTruthy(@Nullable Object obj)
    • isFalsy

      public static boolean isFalsy(@Nullable Object obj)
    • isTripleEqual

      public static boolean isTripleEqual(@Nullable Object o1, @Nullable Object o2)
      Returns true if two objects are same.

      This method mostly behaves similar to Java == operator except that it doesn't return true for null==undefined comparison.

    • coerceToDouble

      public static double coerceToDouble(@Nullable Object d)
      Coerces any object to number using + operation.
    • coerceToInt

      public static int coerceToInt(@Nullable Object d)
      Coerces any object to 32 bit signed number using |0 operation.
    • coerceToBoolean

      public static boolean coerceToBoolean(@Nullable Object b)
      Coerces any object to boolean using !! operation.