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.