Delegated yield (yield star, yield *) in generator functions

后端 未结 3 772

ECMAScript 6 should be bringing generator functions and iterators. A generator function (which has the function* syntax) returns an iterator. The iterator has a

3条回答
  •  臣服心动
    2020-11-27 05:40

    Delegated yield doesn't have to delegate to another generator only, but to any iterator, so the first answer is a bit inconclusive. Consider this simple example:

    `
    function *someGenerator() {
        yield 0;
        yield [1,2,3]
        yield* [1,2,3] 
    }
    
    for (v of someGenerator()) {
        console.log(v);
    }
    
    `
    

    There isn't another function inside the generator itself - yet yield delegates to the iterator of an Array Object Iterator ;-)

提交回复
热议问题