1.next()函数,返回done和value
2. [Symbol.iterator]:迭代器工厂函数
3.[Symbol.iterator](),打印 arr[[Symbol.iterator]()] 的值如下:
class Counter{
constructor(limit){
this.limit=limit
}
[Symbol.iterator](){
let count=1,
limit=this.limit
return {
next(){
if(count<=limit){
return {done:false,value:count++}
}
else{
return {done:true,value:undefined}
}
}
}
}
}
let counter=new Counter(3)
for(let i of counter){console.log(i)}