const obj = {
name: 'zs',
age: 18,
[Symbol('secert')]: '秘密'
}
Object.prototype[Symbol.iterator] = function () {
let _this = this
const keys = Reflect.ownKeys(_this)
let index = 0
return {
next() {
if(index<keys.length) {
return { value: _this[keys[index++]], done: false }
} else {
return { value: undefined, done: true }
}
}
}
}
for (value of obj) {
console.log(value)
}