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
530
rubygems.next
qrush
5
460
how to find GIFs
qrush
10
540
RubyMotion: The sleeper has awakened!
qrush
5
870
Basecamp Next: Code Spelunking
qrush
62
9k
m: a better Ruby Test::Unit runner
qrush
2
560
Test Driven Development
qrush
14
1.4k
Lapidary: The Art of Gemcutting
qrush
2
520
Other Decks in Programming
See All in Programming
sappoRo.R #12 初心者セッション
kosugitti
0
230
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
370
Linux && Docker 研修/Linux && Docker training
forrep
23
4.5k
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
5
3.8k
CloudNativePGがCNCF Sandboxプロジェクトになったぞ! 〜CloudNativePGの仕組みの紹介〜
nnaka2992
0
220
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
110
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
260
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
490
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
210
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
240
Software Architecture
hschwentner
6
2.1k
Conform を推す - Advocating for Conform
mizoguchicoji
3
680
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
67
11k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Practical Orchestrator
shlominoach
186
10k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Docker and Python
trallard
44
3.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Building an army of robots
kneath
302
45k
The Language of Interfaces
destraynor
156
24k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
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