JS_SetElement 编辑

Assign a value to a numeric property of an object.

Syntax

/* Added in SpiderMonkey 31 */

bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              JS::HandleValue v);

bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              JS::HandleObject v);

bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              JS::HandleString v);

bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              int32_t v);

bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              uint32_t v);

bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              double v);


/* Obsolete since JSAPI 29 */
bool
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
              JS::MutableHandleValue vp);
NameTypeDescription
cxJSContext *The context in which to set the element. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
objJS::HandleObjectThe object to modify, commonly an Array object.
indexuint32_tIndex number of the element to set.
vJS::HandleValue or JS::HandleObject or JS::HandleString or int32_t or uint32_t or doubleThe value to assign to the element. Added in SpiderMonkey 31
vpJS::MutableHandleValueIn/out parameter. *vp is the value to assign to the element. JS_SetElement ordinarily leaves *vp unchanged, but a JSClass.addProperty hook or non-default setter may modify it. Obsolete since JSAPI 29

Description

JS_SetElement assigns a value to a numeric property of an object. It behaves like the JavaScript expression obj[index] = v.

On success, JS_SetElement returns true. On error or exception, JS_SetElement returns false.

Obsolete since JSAPI 29

On success, JS_SetElement returns true and the value left in *vp is left unchanged unless an addProperty hook or setter modified it. On error or exception, JS_SetElement returns false and the value left in *vp is unspecified.

See Also

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

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

发布评论

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

词条统计

浏览:91 次

字数:4343

最后编辑:6年前

编辑次数:0 次

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