BT
x Share your thoughts on trends and content!

CoffeeScript 1.9 is Available, Introduces Generators Support

by Sergio De Simone on Feb 09, 2015 |

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

Relevance
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
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.