This document is a CoffeeScript cheat sheet that provides a concise reference to CoffeeScript syntax and features. It includes sections on usage, functions, arrays, objects, inheritance, and higher order functions. The cheat sheet covers topics such as CoffeeScript compilation, parameters, destructuring assignment, filtering, mapping, and reducing arrays. It also provides examples of CoffeeScript classes, inheritance, and overriding class methods.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
56 views
Coffeescript
This document is a CoffeeScript cheat sheet that provides a concise reference to CoffeeScript syntax and features. It includes sections on usage, functions, arrays, objects, inheritance, and higher order functions. The cheat sheet covers topics such as CoffeeScript compilation, parameters, destructuring assignment, filtering, mapping, and reducing arrays. It also provides examples of CoffeeScript classes, inheritance, and overriding class methods.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
CoffeeScript Cheat Sheet
by Dimitrios Mistriotis (dimitrios) via cheatography.com/336/cs/167/
Usage Higher Order (cont) Arrays
-c, --compile doubles = (twice x for x in [1..6]) [1..5] == [1, 2, 3, 4, 5]
-i, --interactive [1...5] == [1, 2, 3, 4] # extra dot Objects [3..1] == [3, 2, 1] -o, --output [DIR] fourNumberArray = [1, 2, 3, 4] meglomaniac = {} -p, --print fourNumberArray.push(5, 6) beforeEach -> -e, --eval fourNumberArray == [1, 2, 3, 4, 5, 6] meglomaniac = --nodejs [1..10][3..5] == [4, 5, 6] # range slicing mastermind: 'The Monarch' "my string"[0..1] == "my" # string slicing most commonly used parameters from henchwoman: 'Dr Girlfriend' #iterate with hasOwnProperty check coffeescript.org theBomb: true for own key, value of object # ? existence operator copyOfArray = array.slice() Functions meglomaniac.theBomb? == true meglomaniac.theDetonator? == false #Last expression value is return value Array Reduction # properties can be added and deleted fill = (container, liquid = "coffee") -> meglomaniac.mastermind2 = 'Agent Smith' # Javascript style "Filling the #{container} with #{liquid}..." delete meglomaniac.mastermind total = (i, a) -> i + a # internal variables override outer ones # prototype to add to all projects reduction = [1..3].reduce total == 6 message = 'Outer' Circle = (radius) -> @radius = radius # Coffeescript-style getMessage = -> message '@' = 'this context' In Coffeescript total = 0 overrideMessage = -> message = 'Inner' sum = (a) -> total = total + a overrideMessage() == 'Inner' Inheritance sum x for x in [1..3] # supports splats total == 6 returnAllArgs = (allargs...) -> allargs # running example from Muppets returnAllArgs('first', 'second', 'third') == class Muppet MDN Documentation: ['first', 'second', 'third'] constructor: (@age, @hobby) -> http://tinyurl.com/arreduce returnAllButFirst = (firstArg, rest...) -> rest answerNanny: -> "Everything's cool!" returnAllButFirst('first', 'second', 'third') == class SwedishChef extends Muppet Credits ['second', 'third'] constructor: (age, hobby, @mood) -> This cheat sheet is (mostly) based on work #destructuring assignment super(age, hobby) of sleepyfox, which can be found here: weatherReport = (location) -> [location, 22, cook: -> 'Mmmm soup!' https://github.com/sleepyfox/coffeescript-‐ 'Mostly sunny'] @swedishChef = new SwedishChef 3, koans [city, temperature, forecast] = weathe‐ 'cooking', 'chillin' CoffeeScript @github: rReport 'London' @swedishChef.cook() == 'Mmmm soup!' http://jashkenas.github.com/coffee-script/ city == 'London' #base object temperature == 22 @swedishChef.answerNanny() == "Everyt‐ Misc hing's cool!" Official Site: http://coffeescript.org/ Higher Order #instances to override class methods Book: http://pragprog.com/book/tbcoffee/co‐ gonzo = new Muppet 3, 'daredevil 2 in [1..3] == true ffeescript performer' #Javascript-style filter Smooth CoffeeScript: http://tiny.cc/smo‐ gonzo.answerNanny = -> 'Hehehe!' even = (a) -> a % 2 == 0 othcs [1..6].filter even == [2, 4, 6] Jitter (compiler after modifying files): Hello World # CoffeeScript-style filter https://github.com/TrevorBurnham/jitter odds = (x for x in [1..6] when not even x) echo "console.log 'Hello World'" > hello.c‐ Codeschool Course: # CoffeeScript-style map offee http://www.codeschool.com/courses/coffe‐ twice = (a) -> a * 2 coffee hello.coffee escript
By Dimitrios Mistriotis Published 23rd December, 2011. Sponsored by ApolloPad.com
(dimitrios) Last updated 12th May, 2016. Everyone has a novel in them. Finish cheatography.com/dimitrios/ Page 1 of 2. Yours! https://apollopad.com CoffeeScript Cheat Sheet by Dimitrios Mistriotis (dimitrios) via cheatography.com/336/cs/167/
Logo
By Dimitrios Mistriotis Published 23rd December, 2011. Sponsored by ApolloPad.com
(dimitrios) Last updated 12th May, 2016. Everyone has a novel in them. Finish cheatography.com/dimitrios/ Page 2 of 2. Yours! https://apollopad.com