diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 21:46:22 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 21:46:22 -0500 |
commit | a065e04d529da1d847b5062a12c46d916408bf32 (patch) | |
tree | fe0f8bcec1ff39a3c499a2708222dcf15224ff70 /files/ru/web/javascript/reference/global_objects/iterator/index.html | |
parent | 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (diff) | |
download | translated-content-a065e04d529da1d847b5062a12c46d916408bf32.tar.gz translated-content-a065e04d529da1d847b5062a12c46d916408bf32.tar.bz2 translated-content-a065e04d529da1d847b5062a12c46d916408bf32.zip |
update based on https://github.com/mdn/yari/issues/2028
Diffstat (limited to 'files/ru/web/javascript/reference/global_objects/iterator/index.html')
-rw-r--r-- | files/ru/web/javascript/reference/global_objects/iterator/index.html | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/files/ru/web/javascript/reference/global_objects/iterator/index.html b/files/ru/web/javascript/reference/global_objects/iterator/index.html deleted file mode 100644 index 0a55a44af9..0000000000 --- a/files/ru/web/javascript/reference/global_objects/iterator/index.html +++ /dev/null @@ -1,138 +0,0 @@ ---- -title: Iterator -slug: Web/JavaScript/Reference/Global_Objects/Iterator -tags: - - JavaScript - - Reference -translation_of: Archive/Web/Iterator ---- -<div>{{jsSidebar("Objects")}}</div> - -<div> </div> - -<div class="blockIndicator warning"> -<p><strong>Non-standard.</strong> The <code><strong>Iterator</strong></code> function is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of" title="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for..of</a> loops and the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">iterator protocol</a>.</p> -</div> - -<p>The <code><strong>Iterator</strong></code> function returns an object which implements legacy iterator protocol and iterates over enumerable properties of an object.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre>Iterator(<var>object</var>, [keyOnly])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>object</code></dt> - <dd>Object to iterate over properties.</dd> - <dt><code>keyOnly</code></dt> - <dd>If <code>keyOnly</code> is truthy value, <code>Iterator.prototype.next</code> returns <code>property_name</code> only.</dd> -</dl> - -<h2 id="Description">Description</h2> - -<p>Returns <code>Iterator</code> instance that iterates over <code>object</code>. <code>Iterator</code> instance returns <code>[property_name, property_value]</code> array for each iteration if <code>keyOnly</code> is falsy, otherwise, if <code>keyOnly</code> is truthy, it returns <code>property_name</code> for each iteration. If <code>object</code> is the <code>Iterator</code> instance or Generator instance, it returns <code>object</code> itself.</p> - -<h2 id="Properties">Properties</h2> - -<dl> - <dt><code><strong>Iterator.prototype[@@iterator]</strong></code></dt> - <dd>Returns a function that returns iterator object.</dd> -</dl> - -<h2 id="Methods">Methods</h2> - -<dl> - <dt><code><strong>Iterator.prototype.next</strong></code></dt> - <dd>Returns next item in the <code>[property_name, property_value]</code> format or <code>property_name</code> only. It throws <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/StopIteration">StopIteration</a></code> if there are no more items.</dd> -</dl> - -<h2 id="Examples">Examples</h2> - -<h3 id="Iterating_over_properties_of_an_object">Iterating over properties of an object</h3> - -<pre><code>var a = { - x: 10, - y: 20, -}; -var iter = Iterator(a); -console.log(iter.next()); // ["x", 10] -console.log(iter.next()); // ["y", 20] -console.log(iter.next()); // throws StopIteration</code></pre> - -<h3 id="Iterating_over_properties_of_an_object_with_legacy_destructuring_for-in_statement">Iterating over properties of an object with legacy destructuring <code>for-in</code> statement</h3> - -<pre><code>var a = { - x: 10, - y: 20, -}; - -for (var [name, value] in Iterator(a)) { - console.log(name, value); // x 10 - // y 20 -}</code></pre> - -<h3 id="Iterating_with_for-of">Iterating with <code>for-of</code></h3> - -<pre><code>var a = { - x: 10, - y: 20, -}; - -for (var [name, value] of Iterator(a)) { // @@iterator is used - console.log(name, value); // x 10 - // y 20 -}</code></pre> - -<h3 id="Iterates_over_property_name">Iterates over property name</h3> - -<pre><code>var a = { - x: 10, - y: 20, -}; - -for (var name in Iterator(a, true)) { - console.log(name); // x - // y -}</code></pre> - -<h3 id="Passing_Generator_instance">Passing Generator instance</h3> - -<pre><code>function* f() { - yield 'a'; - yield 'b'; -} -var g = f(); - -console.log(g == Iterator(g)); // true - -for (var v in Iterator(g)) { - console.log(v); // a - // b -}</code></pre> - -<h3 id="Passing_Iterator_instance">Passing Iterator instance</h3> - -<pre><code>var a = { - x: 10, - y: 20, -}; - -var i = Iterator(a); - -console.log(i == Iterator(i)); // true</code></pre> - -<h2 id="Specifications">Specifications</h2> - -<p>Non-standard. Not part of any current standards document</p> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<p>Not supported. Used to be in Firefox in versions prior to Firefox 57.</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Iterators_and_Generators" title="/en-US/docs/JavaScript/Guide/Iterators_and_Generators">Iterators and Generators</a></li> - <li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/StopIteration">StopIteration</a></code></li> -</ul> |