for-of example should use array destructuring to group-assign without a temp
BrendanEich opened this issue · 0 comments
BrendanEich commented
Instead of
var fibonacci = {
[Symbol.iterator]() {
var pre = 0, cur = 1;
return {
next() {
var temp = pre; pre = cur; cur += temp;
return { done: false, value: cur }
}
}
}
}
use this:
let fibonacci = {
[Symbol.iterator]() {
let pre = 0, cur = 1;
return {
next() {
[pre, cur] = [cur, pre + cur];
return { done: false, value: cur }
}
}
}
}
I threw in let
usage over var
for free :-P.
/be