var obj = {
name: 'AAA',
age: 23,
address: '广州'
}
Object.defineProperty(obj, Symbol.iterator, {
writable: false,
enumerable: false,
configurable: true,
value: function() {
var self = this;
var index = 0;
var keys = Object.keys(self);
return {
next: function() {
return {
value: self[keys[index++]],
done: index > keys.length
}
}
}
}
})
for (const val of obj) {
console.log(`属性值为:${val}`);
}