-
Notifications
You must be signed in to change notification settings - Fork 0
CoffeeScript
CoffeeScript.org has tons of examples of CoffeeScript code side-by-side with its corresponding JavaScript (so you can see how much code you'll save).
Do not use backticks. (Backticks let you embed JavaScript code in CoffeeScript to be passed unfiltered directly into the compiled JavaScript.) CoffeeScript is designed to protect you from the bad parts of JavaScript. If you find yourself wanting to use some JavaScript feature that doesn't exist in CoffeeScript, you're probably doing it wrong. Figure out how to do what you want to do in CoffeeScript.
CoffeeScript compiles to JavaScript, so it's important to understand the good and bad parts of JavaScript when working with CoffeeScript. See our JavaScript guide.
CoffeeScript resolves some of the bad parts of JavaScript. For example, CoffeeScript adds var
to variable names when compiling to JavaScript, so you don't need to worry about accidental global variables. (Use window.SomeNamespace = { ... }
to define a global variable namespace in web browsers.) Also, ==
and !=
in CoffeeScript compile to ===
and !==
in JavaScript, so you don't have to worry about that either. However, some of the bad parts are still present in CoffeeScript. See more details in the Little Book of CoffeeScript, below.
To dive deeper into how to use classes, comprehensions, and other concepts, read the quick Little Book of CoffeeScript.