Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
CoffeeScript - Spartan Javascript
Nick Quaranto
January 16, 2013
Programming
0
390
CoffeeScript - Spartan Javascript
Going over the basics of CoffeeScript. Given at BarCampRochester and BuffaloJS.
Nick Quaranto
January 16, 2013
Tweet
Share
More Decks by Nick Quaranto
See All by Nick Quaranto
The GraphQL Way: A new path for JSON APIs
qrush
288
19k
Awesome Extractions Done Quick
qrush
1
430
rubygems.next
qrush
5
260
how to find GIFs
qrush
10
500
RubyMotion: The sleeper has awakened!
qrush
5
640
Basecamp Next: Code Spelunking
qrush
62
8.6k
m: a better Ruby Test::Unit runner
qrush
2
430
Test Driven Development
qrush
14
1.2k
Lapidary: The Art of Gemcutting
qrush
2
320
Other Decks in Programming
See All in Programming
C言語でメモリ管理を考えた話
hkawai
0
180
読みやすいコードを書こう
yutorin
0
380
人類には難しいZynqで組み込みRust
ikemori
0
480
Loom is Blooming
josepaumard
3
520
Microsoft Teams の 会議アプリ開発のはじめかた / How to start Microsoft Teams app development
karamem0
0
1.5k
New Relicを使った Observabilityの実現方法と活用例 / gocon 2022 spring after talk
budougumi0617
0
950
TechFeed Conference 2022 - Kotlin Experimental
jmatsu
0
580
既存のプロジェクトにKMMを導入するための対応策
martysuzuki
2
290
Groovy Roadmap
paulk
7
13k
About Type Syntax Proposal
quramy
1
940
microCMS × imgixを活用して品質とレスポンスを両立したポートフォリオサイトを作成した話
takehitogoto
0
390
Android Architecture Design With Koin
agiuliani
0
210
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
19
1.1k
Build your cross-platform service in a week with App Engine
jlugia
219
17k
Ruby is Unlike a Banana
tanoku
91
9.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
343
17k
YesSQL, Process and Tooling at Scale
rocio
157
12k
Learning to Love Humans: Emotional Interface Design
aarron
261
37k
Why You Should Never Use an ORM
jnunemaker
PRO
47
5.5k
GraphQLとの向き合い方2022年版
quramy
16
8.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
29
4.3k
Gamification - CAS2011
davidbonilla
75
3.9k
The Web Native Designer (August 2011)
paulrobertlloyd
74
1.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
238
11k
Transcript
R R CoffeeScript @qrush BarCampRoc Apr 2013 Spartan JavaScript
None
JavaScript as a language is Not Verbose
Good JS is OO
Good JS is Concise
CoffeeScript is “Just JS”
CoffeeScript writes Good JS
CoffeeScript is Spartan!
a new battle! http://www.flickr.com/photos/pshab/1578426589/
the closest I’ve felt to the power I had 20
years ago in Smalltalk ~Ward Cunningham
it was the first time I experienced language envy ~DHH
I use both ~Brendan Eich
function foo() { }
function foo() func foo() function foo( function foo() func foo()
function foo( function foo() func foo() function foo( function foo() func
function foo() func foo() function foo( function foo() func foo()
function foo( function foo() func foo() function foo( function foo() func
this
this
foo = function() { return 1 + 1; }
foo = () -> 1 + 1
bar = function(x) { return x + 1; }
bar = (x) -> x + 1
_.bind(fn, obj) http://underscorejs.org/#bind http://coffeescript.org#fat_arrow
baz = () => this.foo()
foz = () => @foo()
$ -> new ItemsRouter() Backbone.history.start()
$ -> new ItemsRouter() Backbone.history.start()
more features
indents are scope
last statements implicitly return
all vars local by default
easier object syntax
title: "Sparta!" author: name: "Leonidas" handle: "theking" apples: 1
string interpolation
var html = "<option value='" + this.id + "'>" +
this.get("title") + "</option>";
"<option value='#{@id}'> #{@get("title")}</option>"
"<option value='#{@id}'> #{@get("title")}</option>"
inheritance actually works
class Item extends Backbone.Model url: -> "/events/#{@id}"
loops are less painful
None
nums = [4, 5, 6] for i in nums console.log
i 4 5 6
comprehensions compact code
nums = [1, 2, 3] [ 1, 2, 3 ]
sq = (n * n for n in nums) [ 1, 4, 9 ]
nums = [1, 2, 3] [ 1, 2, 3 ]
sq = (n * n for n in nums) [ 1, 4, 9 ]
conditionals and loops can be inline
console.log("Sparta!") if true Sparta! console.log("Persia!") unless false Sparta!
x = 6 6 x += 1 while x <
10 [ 7, 8, 9, 10 ] x 10
get existential
spear? false spear = -> "Throw!" [Function] spear? true
window.bcx ?= {} {}
startWaiting: -> @waitTimeout ?= setTimeout => @$container.addClass "waiting" , 300
stopWaiting: -> if @waitTimeout? clearTimeout @waitTimeout @waitTimeout = null @$container.removeClass "waiting"
meet your enemies
None
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/
debugging is not terrible
http://alexspeller.com/
some silly keywords
yes, true, on no, false, off
more info • http://coffeescript.org • http://coffeescript.codeschool.com/ • http://robots.thoughtbot.com/post/ 9251081564/coffeescript-spartan- javascript