concept CoffeeScript in category scala

appears as: CoffeeScript
Play for Scala: Covers Play 2

This is an excerpt from Manning's book Play for Scala: Covers Play 2.

Recent years have seen advances in browser support and runtime performance for CSS stylesheets and client JavaScript, along with more variation in how these technologies are used. One trend is the emergence of new languages that are compiled to CSS or JavaScript so that they can be used in the web browser. Play supports one of each: LESS and CoffeeScript, languages that improve on CSS and JavaScript, respectively.

CoffeeScript (http://coffeescript.org) is a language that compiles to JavaScript, consisting mainly of syntactic improvements over JavaScript. Instead of curly braces, CoffeeScript uses indentation and has a very short function literal notation. Consider the following example in JavaScript:

math = {
  root: Math.sqrt,
  square: square,
  cube: function(x) {
    return x * square(x);
  }
};

In CoffeeScript, you’d write this as follows:

math =
  root:   Math.sqrt
  square: square
  cube:   (x) -> x * square x

No curly braces are used around the object, and the function definition is more concise. If you want to learn CoffeeScript, visit http://coffeescript.org, or get the book CoffeeScript in Action by Patrick Lee (Manning).

6.6. Using LESS and CoffeeScript: the asset pipeline

Browsers process HTML with CSS and JavaScript, so your web application must output these formats for browsers to understand them. But these languages aren’t always the choice of developers. Many developers prefer newer versions of these technologies, like LESS and CoffeeScript over CSS and JavaScript. LESS is a stylesheet language that’s transformed to CSS by a LESS interpreter or compiler, whereas CoffeeScript is a scripting language that’s transformed into JavaScript by a CoffeeScript compiler.