Chapter 6. The Little Conclusion
By Jeremy Ashkenas[1]
Youâve reached the end of The Little Book on CoffeeScript, and now you know just about everything youâll need. CoffeeScript is a little language at heart, and if you know JavaScript and have a sense of the philosophy behind the changes that CoffeeScript makes to JavaScript, you should be able to get up and running very quickly indeed.
Philosophy
Unlike most programming languages, CoffeeScript was never designed from the ground up. It has always been an attempt to express core JavaScript concepts in as simple and minimal a syntax as we can find for them.
Letâs take a simple function. To produce the square of x
, we multiply x
by itself. In JavaScript:
var square = function(x) { return x * x; };
To derive the CoffeeScript for this, letâs think through the steps it would take to reduce this function to its essential features.
We can understand the code perfectly well without the semicolons, so letâs drop those.
Instead of using
{
and}
to delimit the body of the function, letâs use the indentation thatâs already present on the page.Itâs clear that weâre defining a new function, so letâs drop the redundant
var
in front of the assignment.Every construct in CoffeeScript should be an expression with a value, so the natural value of a function body is the last line of code it executes ... allowing us to omit the
return
.Finally, we replace
function( input ){ output }
with a function literal that visually represents the idea ...
Get The Little Book on CoffeeScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.