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
An opaque handle to a native JavaScript object. A
JavaScriptObject
cannot be created directly.
JavaScriptObject
should be declared as the return type of a
JSNI method that returns native (non-Java) objects. A
JavaScriptObject
passed back into JSNI from Java becomes the
original object, and can be accessed in JavaScript as expected.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal <T extends JavaScriptObject>
Tcast()
A helper method to enable cross-casting from anyJavaScriptObject
type to any otherJavaScriptObject
type.static JavaScriptObject
Returns a new array.static JavaScriptObject
createArray
(int size) Returns a new array with a given size.static JavaScriptObject
Returns an empty function.static JavaScriptObject
Returns a new object.final boolean
Calls a native JSequals
method if any, otherwise returnstrue
if the objects are JavaScript identical (triple-equals).final int
hashCode()
Calls a native JShashCode
method if any, otherwise uses a monotonically increasing counter to assign a hash code to the underlying JavaScript object.toSource()
Call the toSource() on the JSO.final String
toString()
Makes a best-effort attempt to get a useful debugging string describing the given JavaScriptObject.
-
Constructor Details
-
JavaScriptObject
protected JavaScriptObject()Not directly instantiable. All subclasses must also define a protected, empty, no-arg constructor.
-
-
Method Details
-
createArray
Returns a new array. -
createArray
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
Returns an empty function. -
createObject
Returns a new object. -
cast
A helper method to enable cross-casting from anyJavaScriptObject
type to any otherJavaScriptObject
type.- Type Parameters:
T
- the target type- Returns:
- this object as a different type
-
equals
Calls a native JSequals
method if any, otherwise returnstrue
if the objects are JavaScript identical (triple-equals). -
hashCode
public final int hashCode()Calls a native JShashCode
method 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. -
toSource
Call the toSource() on the JSO. -
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.
-