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
varin 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 that the input of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access