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
520
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
20k
Awesome Extractions Done Quick
qrush
1
500
rubygems.next
qrush
5
430
how to find GIFs
qrush
10
530
RubyMotion: The sleeper has awakened!
qrush
5
830
Basecamp Next: Code Spelunking
qrush
62
8.9k
m: a better Ruby Test::Unit runner
qrush
2
530
Test Driven Development
qrush
14
1.4k
Lapidary: The Art of Gemcutting
qrush
2
480
Other Decks in Programming
See All in Programming
Kotlin 2.0 and Beyond
antonarhipov
2
150
長期運用プロダクトの開発速度を維持し続けるためのリファクタリング実践例
wataruss
8
2.7k
令和トラベルにおけるLLM活用事例:社内ツール開発から得た学びと実践
ippo012
0
150
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
420
GoのIteratorに詳しくなってしまう
inatonix
1
200
Understand the mechanism! Let's do screenshots tests of Compose Previews with various variations / 仕組みから理解する!Composeプレビューを様々なバリエーションでスクリーンショットテストしよう
sumio
3
620
Jakarta EE meets AI
ivargrimstad
1
480
Android開発以外のAndroid開発経験の活かしどころ
konifar
2
970
Amazon BedrockでサーバレスなAIお料理ボットを作成する!!
tosuri13
0
220
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
LangGraphでのHuman-in-the-Loopの実装
os1ma
3
1.1k
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
200
Featured
See All Featured
Making Projects Easy
brettharned
113
5.8k
Why You Should Never Use an ORM
jnunemaker
PRO
53
8.9k
Fireside Chat
paigeccino
31
2.9k
Testing 201, or: Great Expectations
jmmastey
36
7k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
28
1.6k
A Modern Web Designer's Workflow
chriscoyier
691
190k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
0
97
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.1k
Done Done
chrislema
180
16k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
89
16k
The Cost Of JavaScript in 2023
addyosmani
42
5.6k
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