JavaScript迭代器 [英] JavaScript Iterators

查看:80
本文介绍了JavaScript迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览MDN(Mozilla开发者网络)并遇到了迭代器和生成器

I was going through MDN (Mozilla Developer Network) and came across Iterators and generators

很自然地,我尝试了Google Chrome v21页面中提供的代码片段。具体来说,这段代码:

So naturally, I tried the snippets of code given in the page on Google Chrome v21. To be specific, this code:

var it = Iterator(lang);
for (var pair in it)
  print(pair); // prints each [key, value] pair in turn

但是,控制台会返回以下错误消息:

However, the console returns this error message:

ReferenceError: Iterator is not defined

为什么? Iterator函数是否已被弃用?我错过了一点吗?感谢您的帮助和时间: - )

Why's that? Is the Iterator function deprecated or something? Am I missing a point? Thank you for your help and time :-)

推荐答案

来自此主题


V8是ECMAScript的实现,而不是JavaScript。后者是Mozilla制作的ECMAScript的非标准化扩展。

V8 is an implementation of ECMAScript, not JavaScript. The latter is a non-standardized extension of ECMAScript made by Mozilla.

V8旨在与JSC(WebKit / Safari中的ECMAScript实现)插件兼容。因此,它实现了许多ECMAScript的非标准扩展,这些扩展也在JSC中,其中大多数也是Mozilla的JavaScript语言。

V8 is intended to be plug-in compatible with JSC, the ECMAScript implementation in WebKit/Safari. As such it implements a number of non-standard extensions of ECMAScript that are also in JSC, and most of these are also in Mozilla's JavaScript languages.

没有计划添加不在JSC中的非标准功能到V8。

There is no plan to add non-standard features that are not in JSC to V8.

注意:JSC代表 JavaScript核心 - WebKit ECMAScript实现。

Note: JSC stands for JavaScript Core - the WebKit ECMAScript implementation.

这篇关于JavaScript迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆