JS DefineElement

Creates a numeric property on a specified object.

Syntax

JSBool JS_DefineElement(JSContext *cx, JSObject *obj,
    jsint index, jsval value, JSPropertyOp getter,
    JSPropertyOp setter, uintN flags);
Name Type Description
cx JSContext * The context in which to create the new property. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object on which to create the new property.
index jsint The index of the property to define.
value jsval Initial value to assign to the property.
getter JSPropertyOp getProperty method for retrieving the current property value.
setter JSPropertyOp setProperty method for specifying a new property value.
flags uintN Property attributes.

Description

JS_DefineElement defines a numeric property for a specified object, obj.

index is the index of the element being defined. It must fit in a jsval (see INT_FITS_IN_JSVAL). value is a jsval that defines the property's initial value. getter and setter identify the getProperty and setProperty methods for the property, respectively. If you pass NULL values for these entries, JS_DefineElement assigns the default getProperty and setProperty methods to this element. flags contains the property attributes to set for the new property.

On success, JS_DefineElement returns JS_TRUE. Otherwise it returns JS_FALSE.

Notes

While you can assign a setProperty method to a property and set flags to JSPROP_READONLY, the setter method will not be called on this property.

See Also

MXR ID Search for JS_DefineElement

JS_DefineConstDoubles, JS_DefineFunction, JS_DefineFunctions, JS_DefineObject, JS_DefineProperties, JS_DefineProperty, JS_DefinePropertyWithTinyId, JS_DeleteElement, JS_GetArrayLength, JS_GetElement, JS_IsArrayObject, JS_LookupElement, JS_NewArrayObject, JS_SetElement

Document Tags and Contributors

Last updated by: Jorend,