>>>/ Seems to me like it's just a matter of wrapping the relevant bits (which
ones, though?
/>>/ whatever constitutes the loop "body"
/>/
/>/ OK. That's fairly straightforward.
/>/
/>>/ You also will need a finally clause, if the loop body contains any explicit returns.
/>/
/>/ It only does when the iterator claims there are no more things to be had, in which case do I still want to be calling the return() thing?
/
No, you only call 'return' when exiting the loop before the iterator has
indicated that it is 'done'..
Just for the sake of completeness, here is complete translation of
`for-of` to ES5 syntax.
ES6 for-of statement:
---
for (var value of iterable) {
if (doReturn) return;
if (doBreak) break;
if (doContinue) continue;
otherExpression;
}
---
Translated to ES5 syntax:
---
var $iterable = iterable;
if ($iterable === undefined || $iterable === null) {
throw new TypeError();
}
var $iterator = Object($iterable)[Symbol.iterator]();
if (Object($iterator) !== $iterator) {
throw new TypeError();
}
while (true) {
var $nextResult = $iterator.next();
if (Object($nextResult) !== $nextResult) {
throw new TypeError();
}
if ($nextResult.done) {
break;
}
var $nextValue = $nextResult.value;
var $callClose = false;
try {
value = $nextValue;
if (doReturn) { $callClose = true; return; }
if (doBreak) { $callClose = true; break; }
if (doContinue) continue;
otherExpression;
} catch ($exception) {
try {
if ("return" in $iterator) {
$iterator.return();
}
} catch ($ignore) {
// ignore
}
throw $exception;
} finally {
if ($callClose) {
if ("return" in $iterator) {
$iterator.return();
}
}
}
}
---
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss