1、利用生成器来实现迭代:
function* generator () {
let index = 1
while (index <= 10) {
yield index
index ++
}
let gen = generator ()
console.log(Array.from(gen).join(‘,‘)) // 1, 2, 3, 4, 5, 6, 7, 8,9, 10
一些分享
原文:https://www.cnblogs.com/moxTY/p/12228065.html