// 需求 使用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) }
标签:tmpDone,es6,iterator,index,let,stus,tmpval From: https://www.cnblogs.com/moon-yyl/p/17528121.html