JS_SetPropertyAttributes 编辑

Obsolete since JSAPI 26
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Set the attributes for a specified property.

Syntax

JSBool
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj,
    const char *name, unsigned int attrs, JSBool *foundp);

JSBool
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen, unsigned int attrs,
    JSBool *foundp);
NameTypeDescription
cxJSContext *The context in which to set the property attributes. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
objJSObject *Object for which to set property attributes.
nameconst char * or const jschar *Name of the property for which to set attributes.
namelensize_t(in JS_SetUCPropertyAttributes only) The length of name, in characters.
attrsunsigned intAttribute values to set.
foundpJSBool *Out parameter. Flag indicating whether or not the specified property was located.

Description

JS_SetPropertyAttributes sets the attributes for a specified property, name of an object obj. JS_SetUCPropertyAttributes is the Unicode version of the function.

attrs is an unsigned integer containing the attribute value to set. It is the bitwise OR of zero or more of the following values:

FlagPurpose
JSPROP_ENUMERATEProperty is visible in for and in loops.
JSPROP_READONLYProperty is read only.
JSPROP_PERMANENTProperty cannot be deleted.
JSPROP_EXPORTEDProperty can be imported by other objects.
JSPROP_INDEXProperty is actually an index into an array of properties, and is cast to a const char *.

If JS_SetPropertyAttributes cannot locate an object with the specified property, it returns JS_FALSE, and the value left in *foundp is undefined.

If the specified property or the specified object does not exist, foundp is set to JS_FALSE. Then, if the property exists, but is associated with a different object, JS_SetPropertyAttributes returns JS_TRUE. Otherwise, it sets foundp to JS_TRUE, and attempts to set the attributes as specified. If the attributes can be set, JS_SetPropertyAttributes returns JS_TRUE. If not, it returns JS_FALSE.

To get the attributes of a property, use JS_GetPropertyAttributes.

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

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

发布评论

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

词条统计

浏览:109 次

字数:4954

最后编辑:6年前

编辑次数:0 次

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