functionforOf(arr, cb){//const fun = arr.entriesconst fun = arr[Symbol.iterator]if(arr !=null&&typeof fun !=='function'){throwTypeError("arr is not a iterable")}let iterator = arr[Symbol.iterator]();let obj = iterator.next();while(!obj.done){cb(obj.value)
obj = iterator.next()}}
1
2
3
4
5
6
7
8
9
10
11
12
13
// 测试const obj ={k:1}const obj2 ={k:2}const wp =newWeakMap([[obj,1],[obj2,2]])//xconst ws =newWeakSet([[obj,1],[obj2,2]])//xconst map =newMap([[obj,1],[obj2,2]])//√const set =newSet([[obj,1],[obj2,2]])//√const arr = Array.from(ws)//√ []let ddo = wp
forOf(ddo,function(val){
console.log(val,'my forOf')})// for (let i of ddo) {// console.log(i, "for of")// }