{
let arr=['hello','world'];
let map=arr[Symbol.iterator](); //返回false时继续执行,true停止执行!
console.log(map.next());
console.log(map.next());
console.log(map.next());
}
{
let obj={
start:[,,],
end:[,,],
[Symbol.iterator](){
let self=this;
let index=;
let arr=self.start.concat(self.end);
let len=arr.length;
return {
next(){
if(index<len){
return {
value:arr[index++],
done:false //fasle会继续执行
}
}else {
return {
value:arr[index++],
done:true //truee会结束
}
}
}
}
}
}
for(let key of obj){
console.log(key);
}
}