Chapter 1

The road to CoffeeScript

1.1 Why CoffeeScript?

1.2 Running CoffeeScript

coffee>





coffee> 'CoffeeScript!'
'CoffeeScript!'





coffee> 'CoffeeScript!' # Read 'CoffeeScript!'
# Evaluate 'CoffeeScript!' 'CoffeeScript!' # Print the evaluation of 'CoffeeScript!' coffee> # Loop (to start again)





coffee> CTRL-V
------> 'CoffeeScript!'   # Read
.......
.......
....... CTRL-V            # Eval
'CoffeeScript!'           # Print
coffee>                   # Loop





'CoffeeScript!'
# 'CoffeeScript!'





1.3 JavaScript

1.4 Evolving JavaScript

1.5 Creating CoffeeScript

var square = function (x) {
  return x * x;
};





var square = function (x) {
  return x * x
}





var square = function (x) 
  return x * x





square = function (x)
  return x * x





square = function (x) 
  x * x





square = (x) ->
  x * x





square = (x) ->
  x * x





var square = function (x) {
  return x * x;
};





> coffee ?c square.coffee





square = (x) -> x * x         # Read
                              # Compile to JavaScript
                              # Evaluate the resulting JavaScript
# [Function] # Print
# Loop
square 2 # Read # Compile to JavaScript # Evaluate the resulting JavaScript
# 4 # Print
# Loop





1.6 Summary