Questions about the es6 generator

problem description

clipboard.png

clipboard.png

calls throw after the first next (). Why is the console.log (1) in figure 1 not executed? the console.log ("b") in figure 2 is executed.

is because the yield 1; in figure 1 is not surrounded by try, so the generator ends directly. Figure 2 because yield 1 is surrounded by try, so that executing throw will not be treated as a throwing error, does the code continue to go to the next pause yield 2 and return {value: 2, done: false}? Who can explain this more scientifically?

Mar.25,2022

just check the document

Menu