JS_DefineElement 编辑
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_THREADSAFE build, the caller must be in a request on this JSContext . |
obj | JS::HandleObject or JSObject * | The object on which to create the new property. |
index | uint32_t | The index of the property to define. |
value | JS::HandleValue or JS::HandleObject or JS::HandleString or int32_t or uint32_t or double or jsval | Initial value to assign to the property. |
getter | JSNative or JSPropertyOp | getProperty method for retrieving the current property value. |
setter | JSNative or JSStrictPropertyOp | setProperty method 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论