ES 6:Symbol.iterator和@@ iterator之间的区别 [英] ES 6: Difference between Symbol.iterator and @@iterator

查看:221
本文介绍了ES 6:Symbol.iterator和@@ iterator之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在使用 @@ iterator 函数与 Symbol.iterator one:

I was wondering if there was a specific difference in implementing an iterator using the @@iterator function versus the Symbol.iterator one:

在MDN上有一个 Array.prototype。@@ iterator ,但在示例本身中,使用Symbol.iterator作为函数名。这只是更新的版本,而 @@ iterator 不再有效,还是两者都有效?

On MDN, there is a page on Array.prototype.@@iterator, yet in the examples itself, Symbol.iterator is used as the function name. Is this just the updated version and @@iterator is not valid anymore, or are both of them valid?

推荐答案

没有 @@ iterator 函数。该标记产生语法错误 - 仅在规范中使用表示特定符号。

There is no @@iterator function. That token produces a syntax error - it is only used in specification to denote a specific symbol.

如果要在代码中使用该符号,例如要访问数组上的迭代器,您必须使用 Symbol.iterator 。这是 Symbol 类的属性,初始化为 @@ iterator

If you want to use that symbol in your code, e.g. to access iterators on arrays, you have to use Symbol.iterator. Which is a property of the Symbol class initialised to have the value @@iterator.

这篇关于ES 6:Symbol.iterator和@@ iterator之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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