Can I yield from an inner function?

No, you can’t use yield inside of the inner function. But in your case you don’t need it. You can always use for-of loop instead of forEach method. It will look much prettier, and you can use continue, break, yield inside it:

var trivialGenerator = function *(array) {
    for (var item of array) {
        // some item manipulation
        yield item;
    }
}

You can use for-of if you have some manipulations with item inside it. Otherwise you absolutely don’t need to create this generator, as array has iterator interface natively.

Leave a Comment

techhipbettruvabetnorabahisbahis forumueduseduedueduseduseduseduedueduedus