[~/coffee/jump_start_coffeescript/chapter01/casiano(master)]$ coffee coffee> hello = (name) -> "Hello, #{name}!" [Function] coffee> hello('world!') 'Hello, world!!' coffee> hello 'world!' 'Hello, world!!'
Here,
we’re defining and then calling a function, hello
, which accepts a
single parameter, name
.
The CoffeeScript compiler is itself written in CoffeeScript, using the Jison parser generator. The command-line version of coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browse.
To install, first make sure you have a working copy of the latest stable version of Node.js, and npm (the Node Package Manager). You can then install CoffeeScript with npm:
npm install -g coffee-script(Leave off the -g if you don't wish to install globally.)
If you'd prefer to install the latest master version of CoffeeScript, you can clone the CoffeeScript source repository from GitHub, or download the source directly. To install the lastest master CoffeeScript compiler with npm:
npm install -g http://github.com/jashkenas/coffee-script/tarball/masterOr, if you want to install to /usr/local, and don't want to use npm to manage it, open the coffee-script directory and run:
sudo bin/cake install
CoffeeScript includes a (very) simple build system similar to Make
and Rake. Naturally, it's called Cake , and is used for the tasks
that build and test the CoffeeScript language itself. Tasks are
defined in a file named Cakefile, and can be invoked by running
cake [task]
from within the directory. To print a list of all the
tasks and options, just type cake
.
Casiano Rodríguez León