mozilla

Revision 144988 of JS GET CLASS

  • Revision slug: JS_GET_CLASS
  • Revision title: JS GET CLASS
  • Revision id: 144988
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment [[JS GetClass]] moved to [[JS GET CLASS]]: People should be using the macro, not the function.

Revision Content

{{ Jsapi_ref_header("JS_GET_CLASS") }}

Retrieves the class associated with an object.

Syntax

#define JS_GET_CLASS(cx, obj)  /* ... */

#ifdef JS_THREADSAFE
JSClass * JS_GetClass(JSContext *cx, JSObject *obj);
#else
JSClass * JS_GetClass(JSObject *obj);
#endif
Name Type Description
cx JSContext * Any context associated with the runtime in which obj exists.
obj JSObject * Object to get the class from.

Description

JS_GetClass returns a pointer to the JSClass associated with a specified JS object, obj. The application must treat the JSClass as read-only. If obj has no JSClass, this returns NULL.

The signature of JS_GetClass depends on build settings. Use the JS_GET_CLASS macro instead for maximum compatibility across build environments.

To check the type of an object, use JS_HasInstance instead. For a stricter, exact-match-only check, use JS_InstanceOf or JS_GetInstancePrivate.

{{ LXRSearch("ident", "i", "JS_GET_CLASS") }}
{{ LXRSearch("ident", "i", "JS_GetClass") }}

Revision Source

<p>{{ Jsapi_ref_header("JS_GET_CLASS") }}
</p><p>Retrieves the class associated with an object.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">#define <b>JS_GET_CLASS</b>(cx, obj)  /* ... */

#ifdef <a href="en/JS_THREADSAFE">JS_THREADSAFE</a>
<a href="en/JSClass">JSClass</a> * <b>JS_GetClass</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj);
#else
<a href="en/JSClass">JSClass</a> * <b>JS_GetClass</b>(<a href="en/JSObject">JSObject</a> *obj);
#endif
</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>Any context associated with the runtime in which <code>obj</code> exists.</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>Object to get the class from.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_GetClass</code> returns a pointer to the <code><a href="en/JSClass">JSClass</a></code> associated with a specified JS object, <code>obj</code>. The application must treat the <code>JSClass</code> as read-only. If <code>obj</code> has no <code>JSClass</code>, this returns <code>NULL</code>.
</p><p>The signature of <code>JS_GetClass</code> depends on build settings. Use the <code>JS_GET_CLASS</code> macro instead for maximum compatibility across build environments.
</p><p>To check the type of an object, use <code><a href="en/JS_HasInstance">JS_HasInstance</a></code> instead. For a stricter, exact-match-only check, use <code><a href="en/JS_InstanceOf">JS_InstanceOf</a></code> or <code><a href="en/JS_GetInstancePrivate">JS_GetInstancePrivate</a></code>.
</p><p>{{ LXRSearch("ident", "i", "JS_GET_CLASS") }}<br>
{{ LXRSearch("ident", "i", "JS_GetClass") }}
</p>
Revert to this revision