// 对Object进行原型编程 Object.prototype[Symbol.iterator] = function* () { let index = 0; let arr = Object.entries(this); let length = arr.length; while (true) { if (index >= length) { return false } else { let key = arr[index] && arr[index][0]; let text = arr[index] && arr[index][1]; let value = { [key]: text }; index++; yield value } } }; // 测试 const myObj = { a: 1, b: 2, c: 3, } for (const [item] of myObj) { console.log(item); } /* 输出: {a: 1} {b: 2} {c: 3} */