ES6学习笔记六(Iterator和for..of)

{
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);
}
}
上一篇:Devops-day5-Jenkins部署Python+Golang


下一篇:Oracle笔记 八、PL/SQL跳转/判断/循环语句块