What is coffee-script?
The coffee-script npm package is a language that compiles into JavaScript. It provides a more readable and concise syntax compared to JavaScript, making it easier to write and maintain code. CoffeeScript adds syntactic sugar inspired by Ruby, Python, and Haskell to JavaScript, and it compiles one-to-one into the equivalent JavaScript.
What are coffee-script's main functionalities?
Class Definitions
CoffeeScript provides a simple syntax for defining classes and constructors. The '@' symbol is a shorthand for 'this.' in JavaScript.
class Animal
constructor: (@name) ->
speak: -> console.log "#{@name} makes a noise."
Function Definitions
Functions in CoffeeScript are defined using the '->' syntax, which is more concise than JavaScript's 'function' keyword.
square = (x) -> x * x
Array Comprehensions
CoffeeScript supports array comprehensions, allowing for more readable and concise array manipulations.
cubes = (x * x * x for x in [1..10])
String Interpolation
String interpolation in CoffeeScript uses the '#{}' syntax, making it easier to embed expressions within strings.
name = 'world'
greeting = "Hello, #{name}!"
Other packages similar to coffee-script
typescript
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It adds optional static types, classes, and interfaces, making it more suitable for large-scale applications. Unlike CoffeeScript, TypeScript focuses on type safety and tooling support.
babel
Babel is a JavaScript compiler that allows you to use next-generation JavaScript, today. It can transform syntax from ES6/ES7 to ES5, making it compatible with older browsers. Babel focuses on enabling the use of modern JavaScript features, whereas CoffeeScript provides a different syntax altogether.
livescript
LiveScript is a language that compiles to JavaScript and is a fork of CoffeeScript. It aims to provide a more powerful and flexible syntax, including features like pattern matching and function composition. LiveScript is more experimental compared to CoffeeScript.
{
} } {
{ { } }
} }{ {
{ }{ } } _____ __ __
{ }{ }{ { } / ____| / _|/ _|
.- { { } { }} -. | | ___ | |_| |_ ___ ___
( { } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|`-..________ ..-'| | |___| (_) | | | || __/ __/
| | \_____\___/|_| |_| \___|\___|
| ;--.
| (__ \ _____ _ _
| | ) ) / ____| (_) | |
| |/ / | (___ ___ _ __ _ _ __ | |_
| ( / \___ \ / __| '__| | '_ \| __|
| |/ ____) | (__| | | | |_) | |_
| | |_____/ \___|_| |_| .__/ \__|
`-.._________..-' | |
|_|
CoffeeScript is a little language that compiles into JavaScript.
Installation
Once you have Node.js installed:
npm install --global coffeescript
Leave off the --global
if you don’t wish to install globally.
Getting Started
Execute a script:
coffee /path/to/script.coffee
Compile a script:
coffee -c /path/to/script.coffee
For documentation, usage, and examples, see: http://coffeescript.org/
To suggest a feature or report a bug: https://github.com/jashkenas/coffeescript/issues
If you’d like to chat, drop by #coffeescript on Freenode IRC.
The source repository: https://github.com/jashkenas/coffeescript.git
Changelog: http://coffeescript.org/#changelog
Our lovely and talented contributors are listed here: https://github.com/jashkenas/coffeescript/contributors