- CoffeeScript
-
CoffeeScript Paradigm(s) Multi-paradigm: prototype-based, functional, imperative, scripting Appeared in 2009 Designed by Jeremy Ashkenas Developer Jeremy Ashkenas, et al. Stable release 1.1.3 (November 8, 2011 )Influenced by JavaScript, Python, Ruby, Haskell, YAML Influenced MoonScript OS Cross-platform License MIT License Usual filename extensions .coffee Website coffeescript.org CoffeeScript is a programming language that transcompiles to JavaScript. The language adds syntactic sugar inspired by Ruby, Python and Haskell[1] to enhance JavaScript's brevity and readability, as well as adding more sophisticated features like array comprehension and pattern matching. CoffeeScript compiles predictably to JavaScript and programs can be written with less code (typically 1/3 fewer lines) with no effect on runtime performance.[2] Since March 16, 2011, CoffeeScript has been on GitHub's list of most-watched projects.[3]
The language has a relatively large following in the Ruby community, and has been used in production by 37signals.[4] CoffeeScript support is included in Ruby on Rails version 3.1.[5] Additionally, Brendan Eich has referenced CoffeeScript as an influence on his thoughts about the future of JavaScript.[6][7]
Contents
History
On December 13, 2009, Jeremy Ashkenas made the first Git commit of CoffeeScript with the comment: "initial commit of the mystery language."[8] CoffeeScript was created after reading the "Create Your Own Programming Language" ebook.[9] The compiler was written in Ruby. On December 24, he made the first tagged and documented release, 0.1.0. On February 21, 2010, he committed version 0.5, which replaced the Ruby compiler with one written in pure CoffeeScript. By that time the project had attracted several other contributors on GitHub, and was receiving over 300 page hits per day.
On December 24, 2010, Ashkenas announced the release of stable 1.0.0 to Hacker News, the site where the project was announced for the first time.[10][11]
Examples
A common JavaScript snippet using the jQuery library is
$(document).ready(function() { // Initialization code goes here });
Or even just
$(function() { // Initialization code goes here });
In CoffeeScript, the
function
keyword is replaced by the->
symbol, and indentation is used instead of curly braces, as in Python and Haskell. Also, parentheses can usually be omitted. Thus, the CoffeeScript equivalent of the snippet above is$(document).ready -> # Initialization code goes here
Or just
$ -> # Initialization code goes here
Compiling
The CoffeeScript compiler has been written in CoffeeScript since version 0.5 and is available as a Node.js utility; however, the core compiler does not rely on Node.js and can be run in any JavaScript environment[12]. One alternative to the Node.js utility is the Coffee Maven Plugin, a plugin for the popular Apache Maven build system. The plugin works by utilizing Mozilla Rhino, a JavaScript engine written in Java. The official site at CoffeeScript.org has a "Try CoffeeScript" button in the menu bar; clicking it opens a modal window in which you can enter CoffeeScript, see the JavaScript output, and run it directly in the browser.
References
- ^ The Changelog. Episode 0.2.9 - CoffeeScript with Jeremy Ashkenas, Jul 23, 2010
- ^ Read Write Hack. Interview with Jeremy Ashkenas, Jan 7, 2011
- ^ Github. Popular Watched Repositories
- ^ Carson, Ryan. "New Rails-like Framework from 37signals for HTML5 Mobile Apps", Think Vitamin blog, Nov 8, 2010
- ^ Peek, Joshua. Tweet by Rails Core Team Member on Apr 13, 2011
- ^ Eich, Brendan. "Harmony of My Dreams"
- ^ Eich, Brendan. "My JSConf.US Presentation"
- ^ Github. 'initial commit of the mystery language'
- ^ "Create Your Own Programming Language". createyourproglang.com. http://createyourproglang.com/.
- ^ Hacker News. CoffeeScript 1.0.0 announcement posted by Jeremy Ashkenas on Dec 24, 2010
- ^ Hacker News. Original CoffeeScript announcement posted by Jeremy Ashkenas on Dec 24, 2009
- ^ http://jashkenas.github.com/coffee-script/#installation
Geoffrey Grosenbach; Jeremy Ashkenas, Michael Ficarra (May 12). "Meet CoffeeScript". PeepCode. https://peepcode.com/products/coffeescript.
Further reading
- Burnham, Trevor (July 25, 2011). CoffeeScript: Accelerated JavaScript Development (First ed.). Pragmatic Bookshelf. pp. 136. ISBN 9781934356784. http://pragprog.com/titles/tbcoffee/coffeescript
External links
- Tutorials
- CoffeeScript Cookbook, collection of community sourced CoffeeScript recipes Repository
- The Little Book on CoffeeScript, book introducing CoffeeScript and contrasting it with JavaScript Repository
- Smooth CoffeeScript, book on CoffeeScript and functional programming, also available as an online book
Categories:- JavaScript programming language family
Wikimedia Foundation. 2010.