![Page 1: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/1.jpg)
CoffeeScript
Thursday, September 22, 2011
![Page 2: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/2.jpg)
The State of CoffeeScript
Thursday, September 22, 2011
![Page 3: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/3.jpg)
“It’s just JavaScript”
Thursday, September 22, 2011
![Page 4: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/4.jpg)
Under the Hood
Thursday, September 22, 2011
![Page 5: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/5.jpg)
Scope.prototype.find = function(name, options) { if (this.check(name, options)) { return true; } this.add(name, 'var'); return false;};
Thursday, September 22, 2011
![Page 6: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/6.jpg)
Syntax + Semantics + Goodies
var square = function(x) { return x * x;};
Thursday, September 22, 2011
![Page 7: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/7.jpg)
# Functions...
square = (x) -> x * x
![Page 8: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/8.jpg)
# Literals.
stooges = ['Moe', 'Curly', 'Larry']
elements = { hydrogen: 1, silicon: 14, uranium: 92}
![Page 9: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/9.jpg)
# Whitespace for blocks.
today = "Monday"
if today is "Monday" console.log "Strange Loop!"else console.log "Awww..."
![Page 10: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/10.jpg)
# Array, Range, and Object comprehensions.
list = ['a', 'b', 'c']
console.log "Hi " + letter for letter in list
console.log("Hi " + letter for letter in list)
for name of process console.log name
for i in [0..10] console.log i
![Page 11: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/11.jpg)
# Even conditional statements.
console.log if false 100else 200
# Even crazy things like a try/catch.
tryResult = try missing.objectcatch err "And the error is: #{err}" console.log tryResult
![Page 12: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/12.jpg)
bestActor = (winner, others...) -> console.log "And the Oscar goes to ... #{winner}!" console.log "(with #{others.length} runners up)"
bestActor 'Gypo Nolan', 'Clark Gable', 'Paul Muni', 'Ludwig Satz'
![Page 13: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/13.jpg)
# The existential operator.
sue = name: 'Sue Jones' age: 27
console.log sue.name.length
console.log sue.non?.existent.property
console.log sue.name.split('').reverse?()
![Page 14: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/14.jpg)
# Class literals.
shanty = """ Now let every man drink off his full bumper, And let every man drink off his full glass; We will drink and be jolly and drown melancholy, And heres to the health of each true-hearted lass. """
class Mariner sing: -> console.log shanty
class UptightSailor extends Mariner sing: -> console.log "I'd rather not."
class Pirate extends Mariner sing: -> super() console.log 'AAAAARRRRRRRRRRRRR!'
new Pirate().sing()
![Page 15: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/15.jpg)
class Person constructor: (@name) -> # body of constructor. introduce: => console.log "Hi, I'm #{@name}." groucho = new Person "Groucho Marx"
sayHi = groucho.introduce
sayHi()
![Page 16: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/16.jpg)
futurists = sculptor: "Umberto Boccioni" painter: "Vladimir Burliuk" poet: name: "F.T. Marinetti" address: [ "Via Roma 42R" "Bellagio, Italy 22021" ]
{poet: {name: name, address: [street, city]}} = futurists
console.log "#{name} lives on #{street}."
![Page 17: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/17.jpg)
# David's web server example:
http = require 'http'
server = http.createServer (req, res) -> res.writeHead 200, 'Content-Type': 'text/plain' res.end 'Ahoy, Strange Loop!'
server.listen 3000console.log 'Listening on 3000'
![Page 18: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/18.jpg)
# Design Decisions
![Page 19: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/19.jpg)
# Significant Whitespace
if condition do action if condition then do action
do action if condition
# Other whitespace constructs, like try/catch.
try thingcatch error recover try thing catch error then recover
![Page 20: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/20.jpg)
# Bound vs. Unbound Functions.
class Book save: -> jQuery.ajax this.url, this.data, (response) -> merge this.data, response.data # Why are unbound functions necessary in JavaScript?
![Page 21: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/21.jpg)
# Executable Classes
class Pirate loot: -> say "Give me the gold!"
# ... and with if/else.
class Pirate if century > 1700 loot: -> say "Give me the gold!" else loot: -> say "¡Dame el oro!"
# ... and with wrapped functions.
class Pirate loot: heartily -> say "Give me the gold!"
![Page 22: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/22.jpg)
# Comprehensions (a little bit of everything)
for item in list process item for key, value of object process value # Own keys...
for own key, value of object process value
# Filtering keys and values.
for num in list when num % 2 is 0 even num
# Value of a comprehension?
![Page 23: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/23.jpg)
B.Y.O.J.
Thursday, September 22, 2011
![Page 24: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/24.jpg)
Build Your OwnJavaScript
Thursday, September 22, 2011
![Page 25: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/25.jpg)
Thursday, September 22, 2011
![Page 26: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/26.jpg)
It’s OK to Cheat.
Thursday, September 22, 2011
![Page 27: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/27.jpg)
OMetaCanopy
JS/CC
ReParse
JSGLRAntlr
Cruiser.Parse
p4js
jsparse
Thursday, September 22, 2011
![Page 28: CoffeeScript, the Rise of "Build Your Own JavaScript"](https://reader035.vdocuments.net/reader035/viewer/2022081519/5550b69cb4c905fa618b4b4f/html5/thumbnails/28.jpg)
});
Thursday, September 22, 2011