Join Ray Villalobos for an in-depth discussion in this video What is CoffeeScript?, part of Learning CoffeeScript.
You might even think of the anonymous closure pattern, and the code looks something like this. Now, this is just the type of thing that I have to look up all the time or have a macro for. Now, look at how much punctuation is in there. There are ten parentheses in there, and what are they really doing in terms of expressing your code? Well, absolutely nothing. Neither are the curly braces or the semi-colons. Let's see how we would do this in CoffeeScript. In CoffeeScript, we would type in the dollar sign and then use the special notation, which means function.
Then I'm going to add in another tab on a new line and use that dollar sign variable to target the h1, just like you would in jQuery. Then I'm going to use a regular jQuery command, append. And then in quotes, I'll type in a word that I want to append. So I'm going to save this, and you can see that CoffeeScript converted it to pretty much what we had before. Now, even if you don't know anything about CoffeeScript, you can see that writing with CoffeeScript is a lot easier. Most of it makes sense. You're doing something with the dollar sign variable and then pretty much just expressing your intentions.
- What is CoffeeScript?
- Setting up a project with Gulp.js
- Adding CoffeeScript to your workflow
- Dealing with array ranges
- Working with conditional statements
- Using loops
- Working with splats