Slide 1

Slide 1 text

R R CoffeeScript @qrush BarCampRoc Apr 2013 Spartan JavaScript

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

JavaScript as a language is Not Verbose

Slide 4

Slide 4 text

Good JS is OO

Slide 5

Slide 5 text

Good JS is Concise

Slide 6

Slide 6 text

CoffeeScript is “Just JS”

Slide 7

Slide 7 text

CoffeeScript writes Good JS

Slide 8

Slide 8 text

CoffeeScript is Spartan!

Slide 9

Slide 9 text

a new battle! http://www.flickr.com/photos/pshab/1578426589/

Slide 10

Slide 10 text

the closest I’ve felt to the power I had 20 years ago in Smalltalk ~Ward Cunningham

Slide 11

Slide 11 text

it was the first time I experienced language envy ~DHH

Slide 12

Slide 12 text

I use both ~Brendan Eich

Slide 13

Slide 13 text

function foo() { }

Slide 14

Slide 14 text

function foo() func foo() function foo( function foo() func foo() function foo( function foo() func foo() function foo( function foo() func

Slide 15

Slide 15 text

function foo() func foo() function foo( function foo() func foo() function foo( function foo() func foo() function foo( function foo() func

Slide 16

Slide 16 text

this

Slide 17

Slide 17 text

this

Slide 18

Slide 18 text

foo = function() { return 1 + 1; }

Slide 19

Slide 19 text

foo = () -> 1 + 1

Slide 20

Slide 20 text

bar = function(x) { return x + 1; }

Slide 21

Slide 21 text

bar = (x) -> x + 1

Slide 22

Slide 22 text

_.bind(fn, obj) http://underscorejs.org/#bind http://coffeescript.org#fat_arrow

Slide 23

Slide 23 text

baz = () => this.foo()

Slide 24

Slide 24 text

foz = () => @foo()

Slide 25

Slide 25 text

$ -> new ItemsRouter() Backbone.history.start()

Slide 26

Slide 26 text

$ -> new ItemsRouter() Backbone.history.start()

Slide 27

Slide 27 text

more features

Slide 28

Slide 28 text

indents are scope

Slide 29

Slide 29 text

last statements implicitly return

Slide 30

Slide 30 text

all vars local by default

Slide 31

Slide 31 text

easier object syntax

Slide 32

Slide 32 text

title: "Sparta!" author: name: "Leonidas" handle: "theking" apples: 1

Slide 33

Slide 33 text

string interpolation

Slide 34

Slide 34 text

var html = "" + this.get("title") + "";

Slide 35

Slide 35 text

" #{@get("title")}"

Slide 36

Slide 36 text

" #{@get("title")}"

Slide 37

Slide 37 text

inheritance actually works

Slide 38

Slide 38 text

class Item extends Backbone.Model url: -> "/events/#{@id}"

Slide 39

Slide 39 text

loops are less painful

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

nums = [4, 5, 6] for i in nums console.log i 4 5 6

Slide 42

Slide 42 text

comprehensions compact code

Slide 43

Slide 43 text

nums = [1, 2, 3] [ 1, 2, 3 ] sq = (n * n for n in nums) [ 1, 4, 9 ]

Slide 44

Slide 44 text

nums = [1, 2, 3] [ 1, 2, 3 ] sq = (n * n for n in nums) [ 1, 4, 9 ]

Slide 45

Slide 45 text

conditionals and loops can be inline

Slide 46

Slide 46 text

console.log("Sparta!") if true Sparta! console.log("Persia!") unless false Sparta!

Slide 47

Slide 47 text

x = 6 6 x += 1 while x < 10 [ 7, 8, 9, 10 ] x 10

Slide 48

Slide 48 text

get existential

Slide 49

Slide 49 text

spear? false spear = -> "Throw!" [Function] spear? true

Slide 50

Slide 50 text

window.bcx ?= {} {}

Slide 51

Slide 51 text

startWaiting: -> @waitTimeout ?= setTimeout => @$container.addClass "waiting" , 300 stopWaiting: -> if @waitTimeout? clearTimeout @waitTimeout @waitTimeout = null @$container.removeClass "waiting"

Slide 52

Slide 52 text

meet your enemies

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

making coffee • Rails: http://guides.rubyonrails.org/ asset_pipeline.html • Jekyll & Rake: https://gist.github.com/4496420 • Node: npm install coffee • Anything else: Less.app http://incident57.com/less/

Slide 55

Slide 55 text

debugging is not terrible

Slide 56

Slide 56 text

http://alexspeller.com/

Slide 57

Slide 57 text

some silly keywords

Slide 58

Slide 58 text

yes, true, on no, false, off

Slide 59

Slide 59 text

more info • http://coffeescript.org • http://coffeescript.codeschool.com/ • http://robots.thoughtbot.com/post/ 9251081564/coffeescript-spartan- javascript