In Python we have yield
which is very similar to that one which is proposed in ES6 (in fact, pythonic co-routines were the main source of inspiration for implementing co-routines in
I wonder what are the reasons for choosing a separate function* ()
syntax for generators compared to just defining “regular” functions with yeilds – just like in python by the way? I’m talking strictly of technical issues and peculiarities. Why it had been decided that a separate form will be more appropriate?
Because code that uses yield
normally as variable would change its meaning:
function test() {
var yield = 3;
return yield + 2 //in current javascript this means return 5
//but if yield syntax was enabled for all
//functions then it would secretly change meaning
}
10