JS_GetPropertyAttrsGetterAndSetter 编辑

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.

Retrieve the attributes, getter, and setter of a specified property.

Syntax

JSBool
JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
    const char *name, unsigned int *attrsp, JSBool *foundp,
    JSPropertyOp *getterp, JSPropertyOp *setterp);

JSBool
JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen,
    unsigned int *attrsp, JSBool *foundp,
    JSPropertyOp *getterp, JSPropertyOp *setterp);

JSBool
JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj,
    jsid id, unsigned int *attrsp, JSBool *foundp,
    JSPropertyOp *getterp, JSPropertyOp *setterp); // Added in SpiderMonkey 1.8.1
NameTypeDescription
cxJSContext *The context in which to perform the property lookup. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
objJSObject *Object from which to retrieve property attributes.
name or idconst char * or const jschar * or jsidThe name of the property to examine.
namelensize_t(only in JS_GetUCPropertyAttrsGetterAndSetter) The length of name in characters; or (size_t) -1 to indicate that name is null-terminated.
attrspunsigned int *Out parameter. Pointer to the storage area into which to place retrieves attributes.
foundpJSBool *Out parameter. Flag indicating whether or not the specified property was located.
getterpJSPropertyOp *Out parameter. On success, *getterp receives a pointer to the getter function for the specified property.
setterpJSPropertyOp *Out parameter. On success, *setterp receives a pointer to the setter function for the specified property.

Description

See JS_GetPropertyAttributes for details about these functions. The only difference is that on success, these functions also get the getter and setter functions for the property.

The JS_GETTER (or JS_SETTER) attribute indicates that the property's getter (or setter) is a JavaScript function, not a C/C++ function. When this attribute is present, the value stored in getterp (or setterp) does not really point to a C/C++ function; it is a JSObject *, pointing to a JavaScript function, cast to type JSPropertyOp. The application may cast it back to JSObject * (using a C cast or a C++ reinterpret_cast) to access the getter/setter function object. For more information about JavaScript getters and setters, see Defining Getters and Setters.

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

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

发布评论

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

词条统计

浏览:85 次

字数:5237

最后编辑:7年前

编辑次数:0 次

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