CoffeeScript language syntax
|
Install NodeJs (htttp://nodejs.org/)
|
|
Install npm (nodejs included)
|
|
npm install coffee-script -g
|
|
~$ coffee src/file.coffee
|
Run CoffeeScript file
|
|
~$ coffee -c -o output/ src/
|
Compile files from src to output
|
|
~$ coffee -e "console.log 'Hello World'"
|
Evaluate CoffeeScript code
|
|
$ coffee --join output/all.js --compile src/*.coffee
|
Concatenate the source CoffeeScript before compiling
|
|
~$ coffee
|
Start Read-eval-print loop
|
|
~$ coffee --output output/ -cw src/
|
Watch directory src for changes
|
|
language = 'CoffeeScript'
|
|
coffee = 'espresso' if morning?
|
|
cups = 0; cups ?= 1
|
|
sugar = count ? 1
|
|
coffee = one?.coffee?().please?.no?.sugar?
|
|
hello = -> console.log "Hello"
|
define function
|
|
hello()
|
call function
|
|
sum = (a, b) -> a + b
|
define function with args
|
|
sum 1, 2
|
call function with args
|
|
sum_multiply = (a, b) -> [ a + b, a * b]
|
define function
|
|
[ sum, multiply ] = sum_multiply 1, 2
|
call function
|
|
myFunc = (param = 'default') -> console.log param
|
define function with default param
|
|
otherFunc = (first, other...) -> conole.log other
|
define function
|
|
otherFunc myArray...
|
call function with array as arguments
|
|
array = [1, 2, 3, 4]
|
Array with numbers from 1 to 4
|
|
array = [1...4]
|
Array with numbers from 1 to 3
|
|
array = [1..3]
|
Array with numbers from 1 to 3
|
|
array1 = array[1..3]
|
Create new array from three items from array
|
|
array[1..3] = [3, 2, 1]
|
Change three items of array
|
|
ground_coffee.reverse()
|
Reverse elements in array
|
|
Math.max [12, 32, 11, 67, 1, 3]...
|
Max element of array
|
|
[1 ,2, 3].concat [ 4, 5, 6]
|
concatenating arrays
|
|
CoffeeScript
|
JavaScript
|
|
this, @
|
this
|
|
is
|
===
|
|
isnt
|
!==
|
|
not
|
!
|
|
and
|
&&
|
|
or
|
||
|
|
true, yes, on
|
true
|
|
false, no, off
|
false
|
|
of
|
in
|
|
in
|
find element in array (No JS equivalent)
|
array = [1....3] Array with numbers from 1 to 4 There is no found dots. only 2 dots and 3 dots available. When i try this the generated array become empty. Please update.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.