CoffeeScript Gets Regrind
Written by Kay Ewbank   
Monday, 10 February 2014

CoffeeScript 1.7 has been released with new features requested by developers.

CoffeeScript is a small language that compiles into the equivalent JavaScript with no interpretation at runtime.

According to the official CoffeeScript website, It aims to expose the good parts of JavaScript in a simple way. You can use any existing JavaScript library seamlessly from CoffeeScript, and the compiled output remains readable, passes through JavaScript Lint without warnings, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.

The ‘Literate Programming’ mode introduced in CoffeeScript 1.5 is optional, and is used to make code more readable. If a file is marked as ‘.litcoffee’. then when the compiler is compiling it to JavaScript, anything that isn't indented is discarded, and only the indented text is compiled. CoffeeScript is among the most popular languages on GitHub, and is supported in frameworks such as Ruby on Rails.

CoffeeScript is described as stable and mostly finished, but this new release does add some new features. In a post on Github about the new version, its creator Jeremy Ashkenas describes the changes (in his own "order of excitement"), starting with support for chaining without parentheses. Until now, you had to use a parenthesis if you wanted to chain functions, as shown in the following example:

$("p.neat").addClass("ohmy").show("slow");

This can now be written as:

$("p.neat")
.addClass "ohmy"
.show "slow"

 

The new release has also added better support for multiline strings, with the ability to wrap long strings such as user-facing messages without breaking your code's indentation, or manually stripping newlines out.

Another improvement is support for expansion for array destructuring. This was the longest open issue on CoffeScript. Until now, if you wanted to get the first and last elements of an array, you’d have to use:

[first, middle..., last] = array

The new version lets you just use

[first, ..., last] = array

Likewise, if you want to get the last element in an array in the current version, you’d use:

last = array[array.length - 1]

The new version lets you use:

[..., last] = array

New mathematical operators have been added in the form of a Power operator (**), floor division operator (//), and a modulo operator that respects negatives (%% ).

The 1.7 release is available on the CoffeeScript site and on Github.

 

More Information

CoffeeScript

 

Related Articles

CoffeeScript Supports Literate Programming

Programming in CoffeeScript (book review)

CoffeeScript: Accelerated JavaScript Development (book review)

JavaScript Assembly Language

JavaScript debugging tools move forward

JavaScript creator talks about the future

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin,  or sign up for our weekly newsletter.

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

Banner


Pico 2W Announced But There Is A Surprise!
25/11/2024

Raspberry Pi released the Pico 2 a few months ago and we have been waiting for the Pico 2W since then. But Pimoroni beat them to the draw with the Pico Plus 2W based on the RM2 radio module and hinted [ ... ]



DuckDB And Hydra Partner To Get DuckDB Into PostgreSQL
11/11/2024

The offspring of that partnership is pg_duckdb, an extension that embeds the DuckDB engine into the PostgreSQL database, allowing it to handle analytical workloads.


More News

Last Updated ( Monday, 10 February 2014 )