I'm studying the use of generators in ECMAScript 6.0 "Harmony" .
I have already been able to understand its basic operation, such as declaration through the function* () { ... }
syntax and the production of values through the yield
operator.
However, I still can not find a satisfactory explanation for the operation of the yield*
operator. In the generators page of the official language wiki , the following code, which would be equivalent to that operator, in terms of the yield
operator:
let (g = <<expr>>) {
let received = void 0, send = true, result = void 0;
try {
while (true) {
let next = send ? g.send(received) : g.throw(received);
try {
received = yield next;
send = true;
} catch (e) {
received = e;
send = false;
}
}
} catch (e) {
if (!isStopIteration(e))
throw e;
result = e.value;
} finally {
try { g.close(); } catch (ignored) { }
}
result
}
I still could not clearly understand the purpose or effect of using this operator. Would anyone explain?