Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CoffeeScript - Spartan Javascript
Search
Nick Quaranto
January 16, 2013
Programming
0
550
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
287
20k
Awesome Extractions Done Quick
qrush
1
520
rubygems.next
qrush
5
460
how to find GIFs
qrush
10
540
RubyMotion: The sleeper has awakened!
qrush
5
860
Basecamp Next: Code Spelunking
qrush
62
9k
m: a better Ruby Test::Unit runner
qrush
2
550
Test Driven Development
qrush
14
1.4k
Lapidary: The Art of Gemcutting
qrush
2
510
Other Decks in Programming
See All in Programming
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
150
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
280
ドメインイベント増えすぎ問題
h0r15h0
2
570
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
240
Amazon Nova Reelの可能性
hideg
0
200
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
300
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
450
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
590
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
4
280
Rubyでつくるパケットキャプチャツール
ydah
0
170
Featured
See All Featured
The Invisible Side of Design
smashingmag
299
50k
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
Into the Great Unknown - MozCon
thekraken
34
1.6k
A better future with KSS
kneath
238
17k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
870
Statistics for Hackers
jakevdp
797
220k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
240
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
How STYLIGHT went responsive
nonsquared
96
5.3k
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