concept CoffeeScript in category java

appears as: CoffeeScript, CoffeeScript
Play for Java

This is an excerpt from Manning's book Play for Java.

CoffeeScript (http://coffeescript.org) is a programming language that compiles to JavaScript. It’s generally considered a cleaner and more readable language than JavaScript, and is gaining popularity. Any .coffee file placed in app/assets will be compiled to the application’s public folder, like LESS files.

CoffeeScript 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 would write this as:

8.5. 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. These languages are not always the choice of developers, however. Many developers prefer technologies like LESS and CoffeeScript over CSS and JavaScript. LESS is a stylesheet language that is transformed into CSS by a LESS interpreter or compiler, whereas CoffeeScript is a scripting language that is transformed into JavaScript by a CoffeeScript compiler.

Spring Roo in Action

This is an excerpt from Manning's book Spring Roo in Action.

12.2.1. What is CoffeeScript?

CoffeeScript is a JavaScript simplification language. It can make your scripts more readable and concise. For example, a data grid loading function in the Dojo JavaScript Toolkit API, which Roo uses to decorate standard HTML controls with client-side validation and rich internet features, may look something like this:

Let’s test the remove feature. Build the add-on using mvn package and then run the Roo shell osgi update command to replace the currently installed CoffeeScript add-on:

$ mvn package
...
$ roo
roo> osgi update
         --bundleSymbolicName org.rooina.addons.coffeescript --url:///...target/
               org.rooina.addons.coffeescript-0.1.0.BUILD-SNAPSHOT.jar

The command takes a bundleSymbolicName to reference the installed add-on, which is defined from the Maven artifactId of the CoffeeScript add-on’s pom.xml file.

Finally, try to issue the CoffeeScript remove method. If it works, you’ll see that the pom.xml file no longer contains the CoffeeScript plug-in.