标签:UNC his on() bsp let for console value 添加
let obj = {
0:"我是0",
1:"我是1",
2:"我是2",
length:3,
//添加[Symbol.iterator]方法
[Symbol.iterator] : function() {
let _this = this;
let index = 0;
return {
next:() => {
let value = _this[index];
let done = (index >= _this.length);
index++;
return {value,done}
}
}
}
};
for(let v of obj){
console.log(v);
}
Object添加Symbol.iterator办法执行for--of
标签:UNC his on() bsp let for console value 添加
原文地址:https://www.cnblogs.com/onceweb/p/13278522.html