From a065e04d529da1d847b5062a12c46d916408bf32 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 21:46:22 -0500 Subject: update based on https://github.com/mdn/yari/issues/2028 --- .../reference/global_objects/iterator/index.html | 188 --------------------- 1 file changed, 188 deletions(-) delete mode 100644 files/zh-cn/web/javascript/reference/global_objects/iterator/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/iterator/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/iterator/index.html b/files/zh-cn/web/javascript/reference/global_objects/iterator/index.html deleted file mode 100644 index 775c8d60d6..0000000000 --- a/files/zh-cn/web/javascript/reference/global_objects/iterator/index.html +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: Iterator -slug: Web/JavaScript/Reference/Global_Objects/Iterator -tags: - - Deprecated -translation_of: Archive/Web/Iterator ---- -
{{jsSidebar("Objects")}}
- -
非标准。 Iterator 函数是一个 SpiderMonkey 专有特性,并且会在某一时刻被删除。为将来使用的话,请考虑使用 {{jsxref("Statements/for...of", "for...of")}} 循环和  迭代协议
- -

Iterator 函数返回一个对象,它实现了遗留的迭代协议,并且迭代了一个对象的可枚举属性。

- -

语法

- -
Iterator(object, [keyOnly])
- -

参数

- -
-
object
-
要迭代属性的对象。
-
keyOnly
-
 如果keyOnly是真值,Iterator.prototype.next 只返回property_name
-
- -

描述

- -

返回迭代了object的Iterator 实例。如果keyOnly为假值,则Iterator 实例返回每次迭代而生成的 [property_name, property_value] 数组,否则,如果keyOnly是真值,则它返回每次迭代的 property_name。如果objectIterator 实例或 {{jsxref("Generator")}} 实例 ,则它返回 object 自身。

- -

属性

- -
-
Iterator.prototype[@@iterator]
-
返回一个函数,它返回符合{{jsxref("Iteration_protocols", "迭代协议", "", 1)}}的迭代对象。
-
- -

方法

- -
-
Iterator.prototype.next
-
返回[property_name, property_value] 格式或property_name 的下一项。 如果没有更多项,抛出 StopIteration
-
- -

示例

- -

迭代一个对象的属性

- -
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
-
- -

使用遗留的解构for-in迭代对象的属性

- -
var a = {
-  x: 10,
-  y: 20,
-};
-
-for (var [name, value] in Iterator(a)) {
-  console.log(name, value);   // x 10
-                              // y 20
-}
-
- -

使用for-of迭代

- -
var a = {
-  x: 10,
-  y: 20,
-};
-
-for (var [name, value] of Iterator(a)) {  // @@iterator is used
-  console.log(name, value);   // x 10
-                              // y 20
-}
-
- -

迭代属性名

- -
var a = {
-  x: 10,
-  y: 20,
-};
-
-for (var name in Iterator(a, true)) {
-  console.log(name);   // x
-                       // y
-}
-
- -

传入 Generator 实例

- -
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
-}
-
- -

传入 Iterator 实例

- -
var a = {
-  x: 10,
-  y: 20,
-};
-
-var i = Iterator(a);
-
-console.log(i == Iterator(i)); // true
-
- -

规范

- -

非标准。不是目前任何标准文档的一部分。

- -

浏览器兼容性

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatNo}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
-
- -

相关链接

- - -- cgit v1.2.3-54-g00ecf