href » CoffeeScript
☕ CoffeeScript is a neat language that compiles down to JavaScript. The best part is that (unlike another language I’m thinking of) the resulting code is easily usable from normal JavaScript. It’s really just a layer of syntactic sugar on top of the base language.
However, there are some major differences:
:
can optionally be used for assignment, instead of=
. On one hand this is nice, as it unifies JSON syntax and normal language syntax. On the other, it feels really, really weird, and makes it harder to see when you’re looking at an object literal vs. normal code.- No
var
keyword, scoping is automatic. - No
function
keyword, functions look more like Python lambdas. - Significant whitespace for scopes, a la Python.
Some of my favorite features:
- Tail conditionals:
number = -42 if opposite_day
- Comprehensions:
lunch = eat(food) for food in foods
- Inheritance and a
super
object - Multiline strings
There’s even an Underscore.coffee, a full port of Underscore.js to CoffeeScript! Awesome.