//迭代器
let arr11:Array<number> = [4, 5, 6]
let it:Iterator<number> = arr11[Symbol.iterator]()
console.log(it.next()) //{ value: 4, done: false }
console.log(it.next()) //{ value: 5, done: false }
console.log(it.next()) //{ value: 6, done: false }
console.log(it.next()) //{ value: undefined, done: true }
type mapKeys = string | number
let set:Set<number> = new Set([11, 22, 33])
let map:Map<mapKeys, mapKeys> = new Map()
map.set('1', '测试1')
map.set('2', '测试2')
function gen(erg:any) {
let it:Iterator<any> = erg[Symbol.iterator]()
let next:any = { done: false }
while(!next.done) {
next = it.next()
if(!next.done) {
console.log(next)
}
}
}
gen(arr)
gen(set)
gen(map)
//生成器
for(let item of map) {
console.log(item)
}