es6 iterator
// 需求 使用for of 便利对象并返回对象数组的值
let banji = {
name:"火箭一班",
stus:[
"limuzi",
"nini",
"zhaoliying",
"xiena"
],
[Symbol.iterator](){
let _this = this
let index = 0
return {
next: function(){
let tmpval = 0
let tmpDone = 0
if( index < _this.stus.length ){
tmpval = _this.stus[index]
tmpDone = false
}else{
tmpval = undefined
tmpDone = true
}
index++
return { value: tmpval,done:tmpDone}
}
}
}
}
for(let v of banji){
console.log("v:",v)
}
浙公网安备 33010602011771号