JS_NewPropertyIterator

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_NewPropertyIterator
  • Revision title: JS_NewPropertyIterator
  • Revision id: 126006
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment 14 words removed

Revision Content

Create an object to iterate over the properties of an object.

Syntax

JSObject * JS_NewPropertyIterator(JSContext *cx, JSObject *obj);
Name Type Description
cx JSContext * The JS context in which to enumerate properties. {{ Jsapi-requires-request() }}
obj JSObject * The object whose properties are to be enumerated.

Description

Create an object to iterate over the enumerable properties of obj, in arbitrary order. (This differs from longstanding for..in loop order, which uses the order in which obj's properties were defined.)

On success, this returns an iterator object that can be passed to JS_NextProperty to fetch the property ids. On error, it returns NULL.

The iterator object created by this function is not a JavaScript Iterator. It is an opaque object with no properties visible from JavaScript.

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

Revision Source

<p>Create an object to iterate over the properties of an object.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">JSObject * <strong>JS_NewPropertyIterator</strong>(JSContext *cx, JSObject *obj);
</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>The JS context in which to enumerate properties.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code>JSObject *</code></td>
<td>The object whose properties are to be enumerated.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p>Create an object to iterate over the enumerable properties of <code>obj</code>, in arbitrary order. (This differs from longstanding <code>for..in</code> loop order, which uses the order in which <code>obj</code>'s properties were defined.)
</p><p>On success, this returns an iterator object that can be passed to <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NextProperty" title="en/JS_NextProperty">JS_NextProperty</a></code> to fetch the property ids. On error, it returns <code>NULL</code>.
</p><p>The iterator object created by this function is not a JavaScript <code><a href="/en/Iterator" title="en/Iterator">Iterator</a></code>. It is an opaque object with no properties visible from JavaScript.
</p><p>{{ LXRSearch("ident", "i", "JS_NewPropertyIterator") }}
</p>
Revert to this revision