Creates a numeric property on a specified object.
Syntax
/* Added in SpiderMonkey 38 (JSAPI 32) */
bool
JS_DefineElement(JSContext *cx, JS::HandleObject obj,
                 uint32_t index, JS::HandleValue value,
                 unsigned attrs,
                 JSNative getter = nullptr, JSNative setter = nullptr);
bool
JS_DefineElement(JSContext *cx, JS::HandleObject obj,
                 uint32_t index, JS::HandleObject value,
                 unsigned attrs,
                 JSNative getter = nullptr, JSNative setter = nullptr);
bool
JS_DefineElement(JSContext *cx, JS::HandleObject obj,
                 uint32_t index, JS::HandleString value,
                 unsigned attrs,
                 JSNative getter = nullptr, JSNative setter = nullptr);
bool
JS_DefineElement(JSContext *cx, JS::HandleObject obj,
                 uint32_t index, int32_t value,
                 unsigned attrs,
                 JSNative getter = nullptr, JSNative setter = nullptr);
bool
JS_DefineElement(JSContext *cx, JS::HandleObject obj,
                 uint32_t index, uint32_t value,
                 unsigned attrs,
                 JSNative getter = nullptr, JSNative setter = nullptr);
bool
JS_DefineElement(JSContext *cx, JS::HandleObject obj,
                 uint32_t index, double value,
                 unsigned attrs,
                 JSNative getter = nullptr, JSNative setter = nullptr);
/* Obsolete since JSAPI 32 */
JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value,
                 JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
| Name | Type | Description | 
|---|---|---|
| cx | JSContext * | The context in which to create the new property. Requires request. In a JS_THREADSAFEbuild, the caller must be in a request on thisJSContext. | 
| obj | JS::HandleObjectorJSObject * | The object on which to create the new property. | 
| index | uint32_t | The index of the property to define. | 
| value | JS::HandleValueorJS::HandleObjectorJS::HandleStringorint32_toruint32_tordoubleorjsval | Initial value to assign to the property. | 
| getter | JSNativeorJSPropertyOp | getPropertymethod for retrieving the current property value. | 
| setter | JSNativeorJSStrictPropertyOp | setPropertymethod for specifying a new property value. | 
| flags | unsigned | Property attributes. Obsolete since JSAPI 32 | 
Description
JS_DefineElement defines a numeric property for a specified object, obj.
index is the index of the element being defined. value is one of
JS::Value,
JSObject,
JSString,
int32_t,
uint32_t, or
double
 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.
Obsolete since JSAPI 32 flags contains the property attributes to set for the new property.
On success, JS_DefineElement returns true. Otherwise it returns false.
Obsolete since JSAPI 32.
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
- bug 959787 - changed parameter types