Skip to content

Instantly share code, notes, and snippets.

@raganwald
Created March 15, 2016 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganwald/18a46dabd324f752d151 to your computer and use it in GitHub Desktop.
Save raganwald/18a46dabd324f752d151 to your computer and use it in GitHub Desktop.
Is this valid or invalid ES6?
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
@raganwald
Copy link
Author

Works on ES6 Fiddle, but not on Babel’s online REPL.

Is this valid or invalid code?

@bignimbus
Copy link

Seems to be functioning in Babel's online REPL on my machine:

screen shot 2016-03-15 at 10 59 42 am

@bignimbus
Copy link

Side note: not sure we can use const in a loop, this is node 5.3.0 on my system:

screen shot 2016-03-15 at 11 06 42 am

@nikitadyumin
Copy link

@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*

@bdukes
Copy link

bdukes commented Mar 15, 2016

@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