Created
March 15, 2016 15:51
-
-
Save raganwald/18a46dabd324f752d151 to your computer and use it in GitHub Desktop.
Is this valid or invalid ES6?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function * append (...iterables) { | |
for (const iterable of iterables) { | |
yield * iterable; | |
} | |
} | |
const lyrics = append(["a", "b", "c"], ["one", "two", "three"], ["do", "re", "me"]); | |
for (const word of lyrics) { | |
console.log(word); | |
} | |
//=> | |
a | |
b | |
c | |
one | |
two | |
three | |
do | |
re | |
me |
@bignimbus
V8 seems to ignore reassignment to constants in a loop, while Firefox does not: 'SyntaxError: invalid for/in left-hand side'
@raganwald
except for consts it seems to work, why shouldn't it?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield*
@raganwald, I agree with @nikitadyumin, the only issue here is const
. Runs fine on Edge (with full generator support) when const
becomes let
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works on ES6 Fiddle, but not on Babel’s online REPL.
Is this valid or invalid code?