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?

1 Answer 1


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
  • so all these new syntax had been introduced only not to introduce new keyword?
    – shabunc
    Nov 8, 2013 at 12:40
  • @shabunc yes, you can't just introduce changes that will break existing websites
    – Esailija
    Nov 8, 2013 at 12:45
  • You can't introduce a new keyword. That would break code that uses that keyword as an identifier. You have to use syntax that is currently illegal. Nov 8, 2013 at 13:22
  • 1
    @shabunc: Correct, and this is a very big reason why languages accumulate technical debt and cruft over time. You're stuck with your short sighted or poor decisions forever, because you can't make breaking changes.
    – Phoshi
    Nov 8, 2013 at 13:32
  • 2
    Yes. That's the problem with success. People actually write programs in your language, and get angry when those programs break. The only solution to that problem is to fail ;-) Nov 8, 2013 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.