[英]Built-in Symbol.asyncIterator in Array
According to MDN Web Docs:根据 MDN Web 文档:
There are currently no built-in JavaScript objects that have the [Symbol.asyncIterator] key set by default.当前没有默认设置 [Symbol.asyncIterator] 键的内置 JavaScript 对象。
My question is how come this is working:我的问题是这是如何工作的:
function promises() {
return [
new Promise(x => setTimeout(() => x(1), 1000)),
new Promise(x => setTimeout(() => x(2), 2000)),
new Promise(x => setTimeout(() => x(3), 3000)),
]
}
for await (x of promises()) console.log(x)
MDN also states that MDN 还指出
The
for await...of
statement creates a loop iterating over async iterable objects as well as on sync iterables, including: built-in String, Array, Array-like objects (eg, arguments or NodeList), TypedArray, Map, Set, and user-defined async/sync iterables - MDN (emphasis mine)for await...of
语句创建一个循环迭代异步可迭代对象以及同步可迭代对象,包括:内置字符串、数组、类数组对象(例如 arguments 或 NodeList)、TypedArray、Map、Set、和用户定义的异步/同步迭代- MDN (强调我的)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.