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);
NameTypeDescription
cxJSContext *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.
objJS::HandleObject or JSObject *The object on which to create the new property.
indexuint32_tThe index of the property to define.
valueJS::HandleValue or JS::HandleObject or JS::HandleString or int32_t or uint32_t or double or jsvalInitial value to assign to the property.
getterJSNative or JSPropertyOpgetProperty method for retrieving the current property value.
setterJSNative or JSStrictPropertyOpsetProperty method for specifying a new property value.
flagsunsignedProperty 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:115 次

字数:8510

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文