JS_HasProperty

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_HasProperty
  • Revision title: JS_HasProperty
  • Revision id: 138487
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment no wording changes; page display name changed to 'JS_HasProperty'

Revision Content

{{ Jsapi_ref_header("JS_HasProperty") }}

Determine whether a JavaScript object has a specified property.

Syntax

JSBool JS_HasProperty(JSContext *cx, JSObject *obj,
   const char *name, JSBool *foundp);

JSBool JS_HasUCProperty(JSContext *cx, JSObject *obj,
   const jschar *name, size_t namelen, JSBool *foundp);


Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{ Jsapi-requires-request() }}
obj JSObject * Object to search on for the property.
name const char * or const jschar * Name of the property to look up.
namelen size_t (only in JS_HasUCProperty) The length of name in characters, or -1 to indicate that name is null-terminated.
foundp JSBool * Non-null pointer to a variable of type JSBool. On success, JS_HasProperty stores JS_TRUE in this variable if obj has a property with the given name, and JS_FALSE if not.

Description

JS_HasProperty examines a specified JS object, obj, its scope and prototype links, for a property with the specified name. JS_HasUCProperty is the corresponding Unicode API.

If the property exists, this function sets *foundp to JS_TRUE and returns JS_TRUE.

If the object obj has no such property, the function sets *foundp to JS_FALSE and returns JS_TRUE (to indicate that no error occurred).

If an error occurs during the search, the function returns JS_FALSE, and the value of *foundp is undefined.

See Also

{{ LXRSearch("ident", "i", "JS_HasProperty") }}

JS_GetProperty, JS_LookupProperty, JS_PropertyStub, JS_SetProperty

Revision Source

<p>{{ Jsapi_ref_header("JS_HasProperty") }}
</p><p>Determine whether a JavaScript object has a specified property.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_HasProperty</strong>(<a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/JSObject" title="en/JSObject">JSObject</a> *obj,
   const char *name, <a href="/en/JSBool" title="en/JSBool">JSBool</a> *foundp);

<a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_HasUCProperty</strong>(<a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/JSObject" title="en/JSObject">JSObject</a> *obj,
   const <a href="/en/jschar" title="en/jschar">jschar</a> *name, size_t namelen, <a href="/en/JSBool" title="en/JSBool">JSBool</a> *foundp);
</pre>
<p><br>
</p>
<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/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>Pointer to a JS context from which to derive runtime information.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="/en/JSObject" title="en/JSObject">JSObject</a> *</code></td>
<td>Object to search on for the property.</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>const char *</code> <em>or</em> <code>const <a href="/en/jschar" title="en/jschar">jschar</a> *</code></td>
<td>Name of the property to look up.</td>
</tr>
<tr>
<td><code>namelen</code></td>
<td><code>size_t</code></td>
<td><em>(only in <code>JS_HasUCProperty</code>)</em> The length of <code>name</code> in characters, or <code>-1</code> to indicate that <code>name</code> is null-terminated.</td>
</tr>
<tr>
<td><code>foundp</code></td>
<td><code><a href="/en/JSBool" title="en/JSBool">JSBool</a> *</code></td>
<td>Non-null pointer to a variable of type <code>JSBool</code>. On success, <code>JS_HasProperty</code> stores <code>JS_TRUE</code> in this variable if <code>obj</code> has a property with the given <code>name</code>, and <code>JS_FALSE</code> if not.</td>
</tr> </tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_HasProperty</code> examines a specified JS object, <code>obj</code>, its scope and prototype links, for a property with the specified <code>name</code>. <code>JS_HasUCProperty</code> is the corresponding Unicode API.
</p><p>If the property exists, this function sets <code>*foundp</code> to <code>JS_TRUE</code> and returns <code>JS_TRUE</code>.
</p><p>If the object <code>obj</code> has no such property, the function sets <code>*foundp</code> to <code>JS_FALSE</code> and returns <code>JS_TRUE</code> (to indicate that no error occurred).
</p><p>If an error occurs during the search, the function returns <code>JS_FALSE</code>, and the value of <code>*foundp</code> is undefined.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_HasProperty") }}
</p><p><a href="/en/JS_GetProperty" title="en/JS_GetProperty">JS_GetProperty</a>,
<a href="/en/JS_LookupProperty" title="en/JS_LookupProperty">JS_LookupProperty</a>,
<a href="/en/JS_PropertyStub" title="en/JS_PropertyStub">JS_PropertyStub</a>,
<a href="/en/JS_SetProperty" title="en/JS_SetProperty">JS_SetProperty</a>
</p>
Revert to this revision