CoffeeScript
Paradigm | Multi-paradigm: prototype-based, functional, imperative, scripting |
---|---|
Designed by | Jeremy Ashkenas |
Developer | Jeremy Ashkenas, et al. |
First appeared | 2009 |
Stable release | 0.6.2
/ May 15, 2010 |
OS | Cross-platform |
License | MIT License |
Filename extensions | .coffee |
Website | http://coffeescript.org |
Influenced by | |
JavaScript, Ruby, Python |
CoffeeScript is a programming language that compiles statement-by-statement to JavaScript. The language adds syntactic sugar inspired by Ruby and Python to enhance JavaScript's brevity and readability, as well as adding more sophisticated features like array comprehension and pattern matching.
Examples
A common JavaScript snippet using the jQuery library is
$(document).ready(function() {
// Initialization code goes here
});
In CoffeeScript, the function
keyword is replaced by the ->
symbol, and indentation is used instead of curly braces (except when defining an associative array), as in Python. Also, parentheses can usually be omitted. Thus, the CoffeeScript equivalent of the snippet above is
$(document).ready ->
# Initialization code goes here
Compiling
The CoffeeScript compiler has been written in CoffeeScript since version 0.5, and can be run either in the browser or in Node.js.
External links
- CoffeeScript.org - Official site
- GitHub repository