Jump to content

CoffeeScript

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trevor Burnham (talk | contribs) at 03:33, 19 May 2010 (Stub describing CoffeeScript in outline). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
CoffeeScript
ParadigmMulti-paradigm: prototype-based, functional, imperative, scripting
Designed byJeremy Ashkenas
DeveloperJeremy Ashkenas, et al.
First appeared2009
Stable release
0.6.2 / May 15, 2010 (2010-05-15)
OSCross-platform
LicenseMIT License
Filename extensions.coffee
Websitehttp://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.