es6 可迭代对象

var obj = {
    a: 'a',
    b: 'b',
    c: 'c'
}
Object.defineProperty(obj, Symbol.iterator, {
    writeable: false,
    enumerable: false,
    configurable: true,
    value: function () {
        let o = this,
            index = 0,
            keys = Object.keys(o);
        return {
            next: function () {
                return {
                    value: o[keys[index++]],
                    done: index > keys.length
                }
            }
        }
    }
})
for (k of obj) {
    console.log(k);
}
原文地址:https://www.cnblogs.com/jiajiaobj/p/13655017.html