mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-11 00:54:06 +08:00
116 lines
6.1 KiB
HTML
116 lines
6.1 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<p>The initial value of the <code><strong>@@iterator</strong></code> property is the same function object as the initial value of the <a href="Reference/Global_Objects/Set/values" title="values() 方法返回一个 Iterator 对象,这个对象以插入 Set 对象的顺序包含了原 Set 对象里的每个元素。"><code>values</code></a> property.</p>
|
||
<h2 id="语法">语法</h2>
|
||
<pre><code class="language-javascript"><code><em>mySet</em>[Symbol.iterator]</code></code></pre>
|
||
<h3 id="返回值">返回值</h3>
|
||
<p>The <code>Set</code> <strong>iterator</strong> function, which is the <a href="Reference/Global_Objects/Set/values" title="values() 方法返回一个 Iterator 对象,这个对象以插入 Set 对象的顺序包含了原 Set 对象里的每个元素。"><code>values()</code></a> function by default.</p>
|
||
<h2 id="示例">示例</h2>
|
||
<h3 id="Using_iterator()">Using <code>[@@iterator]()</code></h3>
|
||
<pre><code class="language-js">var mySet = new Set();
|
||
mySet.add("0");
|
||
mySet.add(1);
|
||
mySet.add({});
|
||
|
||
var setIter = mySet[Symbol.iterator]();
|
||
|
||
console.log(setIter.next().value); // "0"
|
||
console.log(setIter.next().value); // 1
|
||
console.log(setIter.next().value); // Object
|
||
</code></pre>
|
||
<h3 id="Using_iterator()_with_for..of">Using <code>[@@iterator]()</code> with <code>for..of</code></h3>
|
||
<pre><code class="language-js">var mySet = new Set();
|
||
mySet.add("0");
|
||
mySet.add(1);
|
||
mySet.add({});
|
||
|
||
for (var v of mySet) {
|
||
console.log(v);
|
||
}
|
||
</code></pre>
|
||
<h2 id="规范">规范</h2>
|
||
<table class="standard-table">
|
||
<tbody>
|
||
<tr>
|
||
<th scope="col">规范</th>
|
||
<th scope="col">状态</th>
|
||
<th scope="col">说明</th>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-set.prototype-@@iterator" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Set.prototype[@@iterator]</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td>Initial definition.</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-set.prototype-@@iterator" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">Set.prototype[@@iterator]</small></a></td>
|
||
<td><span class="spec-Draft">Draft</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h2 id="兼容性">兼容性</h2>
|
||
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
|
||
This compatibility table still uses the old format,
|
||
because we haven't yet converted the data it contains.
|
||
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
|
||
<div class="htab">
|
||
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
|
||
<ul>
|
||
<li class="selected"><a>Desktop</a></li>
|
||
<li><a>Mobile</a></li>
|
||
</ul>
|
||
</div><p></p>
|
||
<div id="compat-desktop">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Chrome</th>
|
||
<th>Firefox (Gecko)</th>
|
||
<th>Internet Explorer</th>
|
||
<th>Opera</th>
|
||
<th>Safari</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
||
<td><a href="/en-US/Firefox/Releases/36" title="Released on 2015-02-24.">36</a> (36) [1]</td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div id="compat-mobile">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Android</th>
|
||
<th>Chrome for Android</th>
|
||
<th>Firefox Mobile (Gecko)</th>
|
||
<th>IE Mobile</th>
|
||
<th>Opera Mobile</th>
|
||
<th>Safari Mobile</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
||
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
||
<td>36.0 (36) [1]</td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>[1] From Gecko 17 (Firefox 17 / Thunderbird 17 / SeaMonkey 2.14) to Gecko 26 (Firefox 26 / Thunderbird 26 / SeaMonkey 2.23 / Firefox OS 1.2) the <code>iterator</code> property was used (<a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=907077" rel="noopener">bug 907077</a>), and from Gecko 27 to Gecko 35 the <code>"@@iterator"</code> placeholder was used. In Gecko 36 (Firefox 36 / Thunderbird 36 / SeaMonkey 2.33), the <code>@@iterator</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">symbol</a> got implemented (<a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=918828" rel="noopener">bug 918828</a>).</p>
|
||
<h2 id="请参阅">请参阅</h2>
|
||
<ul>
|
||
<li><a href="Reference/Global_Objects/Set/entries" title="entries() 方法返回一个新的迭代器对象 ,这个对象的元素是类似 [value, value] 形式的数组,value 是集合对象中的每个元素,迭代器对象元素的顺序即集合对象中元素插入的顺序。由于集合对象不像 Map 对象那样拥有 key,然而,为了与 Map 对象的 API 形式保持一致,故使得每一个 entry 的 key 和 value 都拥有相同的值,因而最终返回一个 [value, value] 形式的数组。"><code>Set.prototype.entries()</code></a></li>
|
||
<li><a class="new" href="Reference/Global_Objects/Set/keys" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>Set.prototype.keys()</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Set/values" title="values() 方法返回一个 Iterator 对象,这个对象以插入 Set 对象的顺序包含了原 Set 对象里的每个元素。"><code>Set.prototype.values()</code></a></li>
|
||
</ul>
|
||
</article> |