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);
Name | Type | Description |
---|---|---|
cx | JSContext * | 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 . |
obj | JS::HandleObject | Object to which this new object belongs as a property. |
name | const char * | Name of the property being defined in obj to hold the new object. |
clasp | const JSClass * | Class to use for the new object. |
proto | JS::HandleObject | Prototype object to use for the new object, or NULL . Obsolete since JSAPI 38 |
flags | unsigned | Property 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->
. Initialization of the new object is up to the caller.constructor
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论