Package com.google.gwt.core.client
Class JavaScriptObject
- java.lang.Object
-
- com.google.gwt.core.client.JavaScriptObject
-
- Direct Known Subclasses:
ArrayBufferNative,ArrayBufferViewNative,CanvasPixelArray,Context2d,DataTransfer,EventTarget,FillStrokeStyle,ImageData,JsArray,JsArrayBoolean,JsArrayInteger,JsArrayMixed,JsArrayNumber,JsArrayString,JsDate,MediaError,NativeEvent,Node,NodeCollection,NodeList,PositionImpl,PositionImpl.CoordinatesImpl,StorageEvent,Style,TextMetrics,TimeRanges,TimeZoneInfo,Touch,XMLHttpRequest
public class JavaScriptObject extends java.lang.ObjectAn opaque handle to a native JavaScript object. AJavaScriptObjectcannot be created directly.JavaScriptObjectshould be declared as the return type of a JSNI method that returns native (non-Java) objects. AJavaScriptObjectpassed back into JSNI from Java becomes the original object, and can be accessed in JavaScript as expected.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJavaScriptObject()Not directly instantiable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends JavaScriptObject>
Tcast()A helper method to enable cross-casting from anyJavaScriptObjecttype to any otherJavaScriptObjecttype.static JavaScriptObjectcreateArray()Returns a new array.static JavaScriptObjectcreateArray(int size)Returns a new array with a given size.static JavaScriptObjectcreateFunction()Returns an empty function.static JavaScriptObjectcreateObject()Returns a new object.booleanequals(java.lang.Object other)Calls a native JSequalsmethod if any, otherwise returnstrueif the objects are JavaScript identical (triple-equals).inthashCode()Calls a native JShashCodemethod if any, otherwise uses a monotonically increasing counter to assign a hash code to the underlying JavaScript object.java.lang.StringtoSource()Call the toSource() on the JSO.java.lang.StringtoString()Makes a best-effort attempt to get a useful debugging string describing the given JavaScriptObject.
-
-
-
Method Detail
-
createArray
public static JavaScriptObject createArray()
Returns a new array.
-
createArray
public static JavaScriptObject createArray(int size)
Returns a new array with a given size.Consider using this method in performance critical code instead of using
createArray(), since this gives more hints to the underlying JavaScript VM for optimizations.
-
createFunction
public static JavaScriptObject createFunction()
Returns an empty function.
-
createObject
public static JavaScriptObject createObject()
Returns a new object.
-
cast
public final <T extends JavaScriptObject> T cast()
A helper method to enable cross-casting from anyJavaScriptObjecttype to any otherJavaScriptObjecttype.- Type Parameters:
T- the target type- Returns:
- this object as a different type
-
equals
public final boolean equals(java.lang.Object other)
Calls a native JSequalsmethod if any, otherwise returnstrueif the objects are JavaScript identical (triple-equals).- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
Calls a native JShashCodemethod if any, otherwise uses a monotonically increasing counter to assign a hash code to the underlying JavaScript object. Do not call this method on non-modifiable JavaScript objects.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code of the object
-
toSource
public java.lang.String toSource()
Call the toSource() on the JSO.
-
toString
public final java.lang.String toString()
Makes a best-effort attempt to get a useful debugging string describing the given JavaScriptObject. In Production Mode with assertions disabled, this will either call and return the JSO's toString() if one exists, or just return "[JavaScriptObject]". In Development Mode, or with assertions enabled, some stronger effort is made to represent other types of JSOs, including inspecting for document nodes' outerHTML and innerHTML, etc.- Overrides:
toStringin classjava.lang.Object
-
-