JS_DefineProperties

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_DefineProperties
  • Revision title: JS_DefineProperties
  • Revision id: 110988
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment tweaks

Revision Content

{{template.Jsapi_ref_header("JS_DefineProperties")}}

Define multiple properties for a single object.

Syntax

JSBool JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
Name Type Description
cx JSContext * The context in which to define the properties. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * The object on which to define new properties.
ps JSPropertySpec * Pointer to an array containing names, ids, flags, and getProperty and setProperty method for the properties to create. The last array element must contain 0-valued members.

Description

JS_DefineProperties creates properties in a specified object, obj.

ps is a pointer to the first element of an array of JSPropertySpec structures. Each array element defines a single property: its name, id, flags, and getProperty and setProperty methods. The name field of the last array element must be NULL. JS_DefineProperties creates one property for each element in the array before the element with a null name field. Each property is defined as though by calling JS_DefinePropertyWithTinyId.

On success, JS_DefineProperties returns JS_TRUE, indicating it has created all properties listed in the array. Otherwise it returns JS_FALSE.

See Also

{{template.LXRSearch("ident", "i", "JS_DefineProperties")}}

JS_DefineConstDoubles, JS_DefineElement, JS_DefineFunction, JS_DefineFunctions, JS_DefineObject, JS_DefineProperty, JS_InitClass

Revision Source

<p>{{template.Jsapi_ref_header("JS_DefineProperties")}}
</p><p>Define multiple properties for a single object.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSBool">JSBool</a> <b>JS_DefineProperties</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj, <a href="en/JSPropertySpec">JSPropertySpec</a> *ps);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="en/JSContext">JSContext</a> *</code></td>
<td>The context in which to define the properties.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>The object on which to define new properties.</td>
</tr>
<tr>
<td><code>ps</code></td>
<td><code><a href="en/JSPropertySpec">JSPropertySpec</a> *</code></td>
<td>Pointer to an array containing names, ids, flags, and <code>getProperty</code> and <code>setProperty</code> method for the properties to create. The last array element must contain <code>0</code>-valued members.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_DefineProperties</code> creates properties in a specified object, <code>obj</code>.
</p><p><code>ps</code> is a pointer to the first element of an array of <code><a href="en/JSPropertySpec">JSPropertySpec</a></code> structures. Each array element defines a single property: its name, id, flags, and <code>getProperty</code> and <code>setProperty</code> methods. The <code>name</code> field of the last array element must be <code>NULL</code>. <code>JS_DefineProperties</code> creates one property for each element in the array before the element with a null <code>name</code> field.  Each property is defined as though by calling <code><a href="en/JS_DefinePropertyWithTinyId">JS_DefinePropertyWithTinyId</a></code>.
</p><p>On success, <code>JS_DefineProperties</code> returns <code>JS_TRUE</code>, indicating it has created all properties listed in the array. Otherwise it returns <code>JS_FALSE</code>.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{template.LXRSearch("ident", "i", "JS_DefineProperties")}}
</p><p><a href="en/JS_DefineConstDoubles">JS_DefineConstDoubles</a>,
<a href="en/JS_DefineElement">JS_DefineElement</a>,
<a href="en/JS_DefineFunction">JS_DefineFunction</a>,
<a href="en/JS_DefineFunctions">JS_DefineFunctions</a>,
<a href="en/JS_DefineObject">JS_DefineObject</a>,
<a href="en/JS_DefineProperty">JS_DefineProperty</a>,
<a href="en/JS_InitClass">JS_InitClass</a>
</p>
Revert to this revision