JavaScript-1.5 Reference

JS_DefineElement Function

Summary

Creates a single element or numeric property for a specified object.

Syntax

JSBool JS_DefineElement(JSContext *cx, JSObject *obj,
    jsint index, jsval value, JSPropertyOp getter,
    JSPropertyOp setter, uintN flags);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Object for which to create the new element.
indexjsintArray index number for the element to define.
valuejsvalInitial value to assign to the element.
getterJSPropertyOpgetProperty method for retrieving the current element value.
setterJSPropertyOpsetProperty method for specifying a new element value.
flagsuintNProperty flags.

Description

JS_DefineElement defines a single element or numeric property for a specified object, obj.

index is the slot number in the array for which to define an element. It may be an valid jsval integer. value is a jsval that defines the element's data type and initial value. getter and setter identify the getProperty and setProperty methods for the element, 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 flags to set for the newly created element. The following table lists possible values you can pass in flags, either singly, or OR'd together:
Flag Purpose

JSPROP_ENUMERATE

Element is visible in for and in loops.

JSPROP_READONLY

Element is read only.

JSPROP_PERMANENT

Element cannot be deleted.

JSPROP_EXPORTED

Element can be imported by other objects.

JSPROP_INDEX

Property is actually an index into an array of properties, and is cast to a const char *.

If it successfully creates the element, 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

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JSPROP_READONLY | JS_AliasElement | 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 ]

This page was generated by APIDOC