public class JSObject extends JSValue
Modifier and Type | Class and Description |
---|---|
static interface |
JSObject.jsexport |
class |
JSObject.Property<T>
A JavaScript object property.
|
Modifier and Type | Field and Description |
---|---|
static int |
JSPropertyAttributeDontDelete
Specifies that the delete operation should fail on a property.
|
static int |
JSPropertyAttributeDontEnum
Specifies that a property should not be enumerated by
JSPropertyEnumerators and JavaScript for...in loops.
|
static int |
JSPropertyAttributeNone
Specifies that a property has no special attributes.
|
static int |
JSPropertyAttributeReadOnly
Specifies that a property is read-only.
|
Constructor and Description |
---|
JSObject()
Called only by convenience subclasses.
|
JSObject(JSContext ctx)
Creates a new, empty JavaScript object.
|
JSObject(JSContext ctx,
java.lang.Class<?> iface)
Creates a new object with function properties set for each method
in the defined interface.
|
JSObject(JSContext ctx,
java.util.Map map)
Creates a new object with the entries in 'map' set as properties.
|
Modifier and Type | Method and Description |
---|---|
JSValue |
__nullFunc() |
boolean |
deleteProperty(java.lang.String prop)
Deletes a property from the object
|
JSObject |
getThis() |
int |
hashCode() |
boolean |
hasProperty(java.lang.String prop)
Determines if the object contains a given property
|
boolean |
isConstructor()
Determines if the object is a constructor
|
boolean |
isFunction()
Determines if the object is a function
|
JSValue |
property(java.lang.String prop)
Gets the property named 'prop'
|
void |
property(java.lang.String prop,
java.lang.Object value)
Sets the value of property 'prop'.
|
void |
property(java.lang.String prop,
java.lang.Object val,
int attributes)
Sets the value of property 'prop'
|
JSValue |
propertyAtIndex(int index)
Returns the property at index 'index'.
|
void |
propertyAtIndex(int index,
java.lang.Object val)
Sets the property at index 'index'.
|
java.lang.String[] |
propertyNames()
Gets the list of set property names on the object
|
JSValue |
prototype()
Gets the prototype object, if it exists
|
void |
prototype(JSValue proto)
Sets the prototype object
|
equals, getContext, isArray, isBoolean, isDate, isEqual, isFloat32Array, isFloat64Array, isInstanceOfConstructor, isInt16Array, isInt32Array, isInt8Array, isNull, isNumber, isObject, isStrictEqual, isString, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, toBoolean, toFunction, toJSArray, toJSON, toNumber, toObject, toString, valueHash, valueRef
public static final int JSPropertyAttributeNone
public static final int JSPropertyAttributeReadOnly
public static final int JSPropertyAttributeDontEnum
public static final int JSPropertyAttributeDontDelete
public JSObject(JSContext ctx)
var obj = {}; // OR
var obj = new Object();
ctx
- The JSContext to create the object inpublic JSObject()
public JSObject(JSContext ctx, java.lang.Class<?> iface)
var obj = {
func1: function(a) { alert(a); },
func2: function(b,c) { alert(b+c); }
};
Where func1, func2, etc. are defined in interface 'iface'. This JSObject
must implement 'iface'.ctx
- The JSContext to create the object iniface
- The Java Interface defining the methods to expose to JavaScriptpublic JSObject(JSContext ctx, java.util.Map map)
ctx
- The JSContext to create object inmap
- The map containing the propertiespublic boolean hasProperty(java.lang.String prop)
prop
- The property to test the existence ofpublic JSValue property(java.lang.String prop)
prop
- The name of the property to fetchpublic void property(java.lang.String prop, java.lang.Object val, int attributes)
prop
- The name of the property to setval
- The Java object to set. The Java object will be converted to a JavaScript object
automatically.attributes
- And OR'd list of JSProperty constantspublic void property(java.lang.String prop, java.lang.Object value)
prop
- The name of the property to setvalue
- The Java object to set. The Java object will be converted to a JavaScript object
automatically.public boolean deleteProperty(java.lang.String prop)
prop
- The name of the property to deletepublic JSValue propertyAtIndex(int index)
index
- The index of the propertypublic void propertyAtIndex(int index, java.lang.Object val)
index
- The index of the property to setval
- The Java object to set, will be automatically converted to a JavaScript valuepublic java.lang.String[] propertyNames()
public boolean isFunction()
public boolean isConstructor()
public JSValue prototype()
public void prototype(JSValue proto)
proto
- The object defining the function prototypespublic JSObject getThis()
public JSValue __nullFunc()