[Javascript] yield*

// Object.prototype[Symbol.iterator] = function() {
//     return Object.values(this)[Symbol.iterator]();
// }

Object.prototype[Symbol.iterator] = function* () {
    // yield* delegates to another generator or iterable object.
    // In this case, it yields each value from the array returned by Object.values(this).
    return yield* Object.values(this);
}

const [a, b] = {a: 1, b: 2}
console.log(a,b)

 

posted @ 2024-08-26 00:20  Zhentiw  阅读(4)  评论(0编辑  收藏  举报