We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

JS DefineElement

Creates a numeric property on a specified object.


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.


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.


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,