SOURCE

const obj = {
    a:'100',
    b:'200',
    c:'300'
}

obj[Symbol.iterator] = function(){
    const self = this,
          keys = Object.keys(self);
    let count = 0;
    console.log(count)
    return {
        next:function(){
            return{
                value:self[keys[count++]],
                done:(count>keys.length)
            }
        }
    }
}

// Object.defineProperty(obj,Symbol.iterator,{
//     writable:false,
//     enumerable:false,
//     configurable:true,
//     value:function(){
//         const self = this,
//               keys = Object.keys(self);
//         let count = 0;
//         return {
//             next:function(){
//                 return {
//                     value:self[keys[count++]],
//                     done:(count < keys.length)
//                 }
//             }
//         }
//     }
// })

// let aaa = obj[Symbol.iterator]()

// aaa.next()
// aaa.next()


for(let val of obj){
    console.log(val)
}
console 命令行工具 X clear

                    
>
console