CoffeeScript Application Development
上QQ阅读APP看书,第一时间看更新

What is CoffeeScript?

CoffeeScript is a programming language. Like most programming languages, it offers control structures to describe the logic of our application, simple data types to store and manipulate information, and functions to encapsulate sections of program execution.

What makes CoffeeScript special is the way it is compiled. When most languages are compiled, they are translated into machine code—low-level instructions to the computer's processor. CoffeeScript is different: when compiled, it is instead translated into JavaScript. We write CoffeeScript code, give it to the CoffeeScript compiler and receive JavaScript code as output. This output can then be passed to anything that consumes JavaScript, such as a browser, or a standalone JavaScript interpreter.

This technique, dubbed transcompilation, allows us to use an alternative language on platforms that only directly support JavaScript. Client-side web development is the most prominent example, since JavaScript is the only supported general-purpose scripting solution on most web browsers. Other platforms such as Node.js and Rhino also offer useful features, but expect JavaScript input. JavaScript is nothing if not prolific, and CoffeeScript allows us to make use of all that existing tooling, but to write our code in a different language.