BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

CoffeeScript 1.9 is Available, Introduces Generators Support

| by Sergio De Simone on Feb 09, 2015. Estimated reading time: 1 minute |

CoffeeScript 1.9 has finally introduced support for long awaited generators, which promise to prevent callback hell and help writing async code.

Generators are, in short functions which can be exited and later re-entered, guaranteeing that their variable bindings will be saved across re-entrances. CoffeeScript 1.9 defines a generator as any function that uses the new yield keyword. This is an example of a simple generator:

foo = ->
    i = 0
    yield i +1
    yield i +2

Calling repeated time the generator will provide the yielded values in succession, that is 1, then 2.

Generators are part of the ECMAScript 6 proposal and have been previously introduced in node 0.11, although they are enabled only when you pass the --harmony-generators flag to node. Generators have been shown to provide an alternative model to callbacks for handling async code, either used in conjunction with promises or not.

Other features provided by CoffeeScript 1.9 are:

  • Improved parsing and error reporting for strings and regexs.
  • New strategy to generate internal compiler variable names implying that parameters declared as @parameter are no longer available as example within the function body.
  • Fixed REPL compatibility with latest version of Node and lo.ja.

CoffeeScript is a language that compiles into JavaScript with the aim to expose the good parts of JavaScript in a simple way.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and dont miss out on content that matters to you

BT