Skip to content

Instantly share code, notes, and snippets.

@benstafford
Created June 5, 2012 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benstafford/2875779 to your computer and use it in GitHub Desktop.
Save benstafford/2875779 to your computer and use it in GitHub Desktop.
coffeescript features

CoffeeScript Features

Probably not comprehensive, and in no particular order...

feature nameexampleinclude?
string interpolation“a#{b}”Y
assignmenta = bY
single-line comment# commentY
integer literal1Y
decimal literal1.1Y
boolean literaltrue/falseY
parentheses for grouping(a or b) and cY
logical operatorsand/or/not/&&/||/!Y
comparison operators/>=/==/!=/is/isntY
member accessa.bY
dynamic member accessa[b]Y
explicit function applicationa(b, c)Y
indentation introduces blocksif a <\n> <indent> bY
`then` introduces blockif a then bY
@-vars@aY
unary existential operatora?Y
conditional executionif a then bY
conditional else clauseif a then b else cY
negated flow control keywordsunless/untilY
in operatora in bY
of operatora of bY
instanceof operatora instanceof bY
negated infix operatorsnot in, not of, not instanceofY
for-infor v, k in a then eY
for-offor k, v of o then eY
filtered loops via whenfor a in b when c then dY
own keyword for hasOwnProperty filterfor own k of o then cY
single-line function literals(a, b) -> cY
parameter-less functions-> aY
multi-line function literals-> <\n> <indent> aY
maths operators/, +, -, %, *Y
array literals[a, b]Y
explicit object literals{a: b}Y
{pre,post}fix {in,de}crement--a, a--, ++a, a++Y
unary +/-+a, -aY
explicit returnreturn 0Y
unconditional looploop then aY
break/continueloop then breakY
classesclass AY
class-extendsclass A extends BY
class proto-assignmentsclass A then m: ->Y
extends operatorA extends BY
switch-when-elseswitch a <\n> when b then cY
try-catch Y
throw operatorthrow aY
new operatornew AY
semicolons as seq operatora; bY
string literals“a”Y
string hex escapes“\x61”Y
string character escapes“\n”Y
string line continuation“<\n>a”Y
regex literals/a/Y
do operatordo aY
slicesa[b..c]  a[b...c]Y
unbounded slicesa[b...]  a[..b]Y
undefined -> void 0undefinedY
null literalnullY
compound assignmenta <binary-op>= bN
boolean aliasesyes/no/on/offN
exponential notation1.2e+4N
bitwise operators&/|/^/~/<</>>/>>>N
soaked member accessa?.bN
dynamic soaked member accessa?[b]N
binary existential operatora ? bN
implicit function applicationa b, cN
proto-member accessa::bN
dynamic proto-member accessa::[b]N
@ as alias for this@N
soaked function applicationa?(b, c)N
while loopwhile a then bN
postfix flow controla if b, c until dN
inclusive ranges[a..b]N
exclusive ranges[a...b]N
bound function literals=>N
object key-omission shorthand{a}N
implicit object literalsa: bN
(splat/rest)-params(a...) ->N
@-params(@a) ->N
named destructuring assignment{a: b} = cN
positional destructuring assignment[a, b] = cN
splat/spread argumentsfn a...N
chained comparisona < b < cN
supersuperN
super with argumentssuper aN
external constructorsclass A then constructor: cN
try-catch-finally N
try-finally N
trytry aN
typeof operatortypeof aN
continue lines ending in binary operatora and <\n> bN
backslash continues linesa \ <\n> + bN
triple-quoted strings“””<\n>   a<\n>”””N
heregexen/// a ///N
ACI in multiline array/object literals[a<\n>b]N
shallow copy of arraya[..]N
splicesa[b..c] = dN
unbounded splicesa[b...] = cN
javascript literals`javascript`N
block comments### comment ###N
default parameters(a = b) ->N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment