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 Intro
Search
David Newell
March 22, 2013
Programming
110
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CoffeeScript Intro
An intro to coffeescript and comparison to javascript.
David Newell
March 22, 2013
More Decks by David Newell
See All by David Newell
Git and Hg
rustedgrail
1
100
Other Decks in Programming
See All in Programming
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
Cloudflare is Agents
chimame
0
150
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.4k
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.4k
その節約、円になってますか?
isamumumu
1
710
プロポーザルを書いてもらう
pvcresin
0
300
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
150
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
310
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
760
VibeCodingからAgenticWorkflowへ
starfish719
0
350
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
310
GitHub's CSS Performance
jonrohan
1033
470k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
VelocityConf: Rendering Performance Case Studies
addyosmani
332
25k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
240
Deep Space Network (abreviated)
tonyrice
0
250
Darren the Foodie - Storyboard
khoart
PRO
3
3.6k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
Transcript
CoffeeScript "It's just JavaScript"
Installation $ npm install -g coffee-script -- OR -- $
https://github.com/jashkenas/coffee-script.git $ sudo bin/cake install -- THEN -- $ coffee -v
Editors with CoffeeScript Extensions •TextMate •Vim •Emacs •gedit •jEdit •IntelliJ
IDEA •IntelliJ RubyMine 4 •NetBeans •Eclipse •Cloud9
Hello World console.log 'hello world' $coffee -c hello.coffee (function() {
console.log('hello world'); }).call(this); console.log 'hello world' $coffee -c --bare hello.coffee console.log('hello world');
Functions greeting = (subject) -> "Hello #{subject}" console.log greeting "CSNY"
======================== var greeting; greeting = function(subject) { return "Hello " + subject; }; console.log(greeting("CSNY"));
Conditionals if typeof 5 is 'number' console.log '5 is odd'
unless 5 % 2 == 1 else throw '5 is not a number' ======================== if (typeof 5 === 'number') { if (5 % 2 !== 1) { console.log('5 is odd'); } } else { throw '5 is not a number'; }
Context setName = (@name) -> ======================== var setName; setName =
function(name) { return this.name = name; };
Fat Arrow save: -> client.open (err, p_client) => client.collection 'worker',
@add ======================== var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; (function() { return client.open(__bind(function(err, p_client) { return client.collection('worker', add); }, this)); });
Arguments (first = 1, rest...) -> ======================== (function() { var
first, rest; first = arguments[0], rest = 2 <= arguments.length ? __slice. call(arguments, 1) : []; if (first == null) { first = 1; }
JSON delta = '\u3094' greekUnicode = {delta} ======================== var delta,
greekUnicode; delta = '\u3094'; greekUnicode = { delta: delta };
Destructuring Assignment metaLanguages = javascript: coffeescript: ["Jeremy", "Ashkenas"] {javascript: {coffeescript:
[first, last]}} = metaLanguages ======================== metaLanguages = { javascript: { coffeescript: ["Jeremy", "Ashkenas"] } }; _ref = metaLanguages.javascript.coffeescript, first = _ref[0], last = _ref[1];
Comprehensions for a in [0..10] by 2 when a %
3 == 0 ======================== var a, _step; for (a = 0, _step = 2; a <= 10; a += _step) { if (a % 3 === 0) { console.log(a); } }
Existential Operator variable? variable ?= "A value" ======================== typeof variable
!== "undefined" && variable !== null; if (typeof variable !== "undefined" && variable !== null) { variable; } else { variable = "A value"; };
Classes class Snake extends Animal constructor: (@noise) -> super() Animal::bark()
var Snake; var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent)
{ for (var key in parent) { if (__hasProp.call(parent, key)) child [key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; Snake = (function() { __extends(Snake, Animal); function Snake(noise) { this.noise = noise; Snake.__super__.constructor.call(this, this.animal); Animal.prototype.noise(); } return Snake;
Watch Out! printing = -> console.log "Watch this" console.log printing
printing() $coffee printing.coffee [Function] Watch this
More Info -- Main Site -- http://jashkenas.github.com/coffee-script/ -- Little Book
on CoffeeScript -- http://arcturo.github.com/library/coffeescript/ -- Smooth-CoffeeScript -- http://autotelicum.github.com/Smooth-CoffeeScript/ -- CoffeeScript Koans -- http://cskoans.herokuapp.com/
Questions -- CoffeeScript Meetup -- http://www.meetup.com/Coffee-Script-New-York/ -- Code and Slides
-- https://github.com/rustedgrail/CoffeeScript-Intro -- CoffeeScript and Node Tower Defense -- http://qqtd.herokuapp.com/