JS_DefineObject 编辑

Create an object that is a property of another object.

Syntax

JSObject *
JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name,
                const JSClass *clasp = nullptr, unsigned attrs = 0);
NameTypeDescription
cxJSContext *The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
objJS::HandleObjectObject to which this new object belongs as a property.
nameconst char *Name of the property being defined in obj to hold the new object.
claspconst JSClass *Class to use for the new object.
protoJS::HandleObjectPrototype object to use for the new object, or NULL. Obsolete since JSAPI 38
flagsunsignedProperty attributes for the new property being defined.

Description

JS_DefineObject creates a new object of the class clasp and assigns it to a new property of an existing object, obj. name is the property name to assign to obj to hold the new object, and flags contains the property attributes to set for the newly created property.

The new object's parent is obj.

JS_DefineObject does not call clasp->constructor. Initialization of the new object is up to the caller.

On success, JS_DefineObject returns a pointer to the new object. On error or exception (if the object cannot be created, the property already exists, or the property cannot be created), JS_DefineObject returns NULL.

This function combines two operations: creating an object and storing it in a property of another object. Use JS_ConstructObject, JS_ConstructObjectWithArguments, or JS_NewObject to create a new object without storing it in a property of another object. Use JS_DefineProperty or JS_DefineElement to create a property without creating a new object.

See also

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

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

发布评论

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

词条统计

浏览:61 次

字数:5988

最后编辑:7年前

编辑次数:0 次

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