Visit Mozilla.org

JS DefineObject

From MDC

Create an object that is a property of another object.

[edit] Syntax

JSObject * JS_DefineObject(JSContext *cx, JSObject *obj,
    const char *name, JSClass *clasp, JSObject *proto,
    uintN flags);
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 JSObject * 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 JSClass * Class to use for the new object.
proto JSObject * Prototype object to use for the new object.
flags uintN Property attributes for the new property being defined.

[edit] Description

JS_DefineObject creates a new object 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 following table lists possible values you can pass in flags, either singly, or OR'd together:

Flag Purpose
JSPROP_ENUMERATE Property is visible to for and in loops.
JSPROP_READONLY Property is read only.
JSPROP_PERMANENT Property cannot be deleted.
JSPROP_EXPORTED Property can be imported by other objects.
JSPROP_INDEX Property is actually an index into an array of properties, and is cast to a const char *.

clasp is a pointer to the base class to use when creating the new object, and proto is an pointer to the prototype upon which to base the new object. If you set proto to NULL, JS sets the prototype object for you. The parent object for the new object is set to obj.

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.

[edit] See Also

LXR ID Search for JS_DefineObject

JS_ConstructObject, JS_DefineConstDoubles, JS_DefineElement, JS_DefineFunction, JS_DefineFunctions, JS_DefineProperties, JS_DefineProperty, JS_DefinePropertyWithTinyId, JS_NewObject, JS_ValueToObject