JS_SetPrototype

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_SetPrototype
  • Revision title: JS_SetPrototype
  • Revision id: 146714
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment Requires request.

Revision Content

{{template.Jsapiref()}}

Sets a JavaScript object's prototype.

Syntax

JSBool JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * Pointer to the object for which to set the prototype.
proto JSObject * Pointer to the prototype to use.

Description

JS_SetPrototype enables you to set the prototype object for a specified object. A prototype object provides properties that are shared by similar JS object instances. Ordinarily you set a prototype for an object when you create the object with JS_NewObject, but if you do not set a prototype at that time, you can later call JS_SetPrototype to do so.

obj is a pointer to an existing JS object, and proto is a pointer to second existing object upon which the first object is based.

If JS_SetPrototype is successful, it returns JS_TRUE. Otherwise, if it cannot create and fill a prototype slot for the object, it returns JS_FALSE.

Notes

Take care not to create a circularly-linked list of prototypes using this function, because such a set of prototypes cannot be resolved by the JS engine.

See Also

Groups Functions
Documents {{template.LXRSearch("ident", "i", "JS_SetPrototype", "LXR ID Search")}}
Entries

JS_GetPrototype, JS_NewObject

Revision Source

<p> 
{{template.Jsapiref()}}
</p><p>Sets a JavaScript object's prototype.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">JSBool JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
</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>JSContext *</code></td>
<td>Pointer to a JS context from which to derive runtime information.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code>JSObject *</code></td>
<td>Pointer to the object for which to set the prototype.</td>
</tr>
<tr>
<td><code>proto</code></td>
<td><code>JSObject *</code></td>
<td>Pointer to the prototype to use.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_SetPrototype</code> enables you to set the prototype object for a specified object. A prototype object provides properties that are shared by similar JS object instances. Ordinarily you set a prototype for an object when you create the object with <code><a href="en/JS_NewObject">JS_NewObject</a></code>, but if you do not set a prototype at that time, you can later call <code>JS_SetPrototype</code> to do so.
</p><p><code>obj</code> is a pointer to an existing JS object, and <code>proto</code> is a pointer to second existing object upon which the first object is based.
</p><p>If <code>JS_SetPrototype</code> is successful, it returns <code>JS_TRUE</code>. Otherwise, if it cannot create and fill a prototype slot for the object, it returns <code>JS_FALSE</code>.
</p>
<h3 name="Notes"> Notes </h3>
<p>Take care not to create a circularly-linked list of prototypes using this function, because such a set of prototypes cannot be resolved by the JS engine.
</p>
<h2 name="See_Also"> See Also </h2>
<table class="fullwidth-table">
<tbody><tr>
<td>Groups</td>
<td><a href="en/JSAPI_Reference#Functions">Functions</a></td>
</tr>
<tr>
<td>Documents</td>
<td>{{template.LXRSearch("ident", "i", "JS_SetPrototype", "LXR ID Search")}}</td>
</tr>
<tr>
<td>Entries</td>
<td>
<p><a href="en/JS_GetPrototype">JS_GetPrototype</a>,
<a href="en/JS_NewObject">JS_NewObject</a>
</p>
</td>
</tr>
</tbody></table>
Revert to this revision