What it is
1:1 Meta-language Compiler
No funny business
Slide 3
Slide 3 text
What it does for you
Easier to read
Easier to write OO code
Better performance
Less verbose
Auto-scoping
Identation is information
Slide 4
Slide 4 text
The basics
name = “RDstation”
valid = true
if valid
console.log name
var name, valid;
name = “RDstation”;
valid = true;
if (valid){
console.log(name);
}
Slide 5
Slide 5 text
The basics: Callbacks
$(‘#cool_button’).click(function(event){
console.log(‘do stuff with’+event);
});
$(‘#cool_button’).click (event) ->
console.log(“do stuff with #{event}”)
$(‘#cool_button’).click ->
console.log(‘do stuff’)
Slide 6
Slide 6 text
The basics: Scoping
out_of_scope = “Can’t touch this!”
$(‘#cool_button’).click (event) ->
console.log(“do stuff with #{event}”)
console.log(out_of_scope) # undefined!
out_of_scope = “Yes we can!”
$(‘#cool_button’).click (event) =>
console.log(“do stuff with #{event}”)
console.log(out_of_scope) # ha!
Slide 7
Slide 7 text
The basics: Iterators
list = [“One”, “Two”, “Three”, “Four”]
for number in list
console.log number
hash = render: true, template: “moustache”
for option,value in hash
console.log “#{option} is #{value}”
Slide 8
Slide 8 text
The basics: Operators
is
isnt
not
and
or
true, yes, on
false, no, off
@, this
of
in
===
!==
!
&&
||
true
false
this
in
Coffeescript Javascript
Slide 9
Slide 9 text
Classes
class Gemstone
constructor: (@name) ->
shine: ->
console.log “#{@name} :sparkles:”
ruby = new Gemstone “Ruby”
ruby.shine()
>> “Ruby :sparkles:”
Slide 10
Slide 10 text
Real world code
LOC
301
LOC
446
Coffeescript Javascript
32% LOC improovement
Slide 11
Slide 11 text
Be aware!
Coffeescript isn’t a
Javascript replacement!
You should know your way
around your Javascript!
DEBUG!