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
2
95
CoffeeScript Intro
An intro to coffeescript and comparison to javascript.
David Newell
March 22, 2013
Tweet
Share
More Decks by David Newell
See All by David Newell
Git and Hg
rustedgrail
1
90
Other Decks in Programming
See All in Programming
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
860
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
180
デミカツ切り抜きで面倒くさいことはPythonにやらせよう
aokswork3
0
250
株式会社 Sun terras カンパニーデック
sunterras
0
360
Devvox Belgium - Agentic AI Patterns
kdubois
1
130
チームの境界をブチ抜いていけ
tokai235
0
190
ALL CODE BASE ARE BELONG TO STUDY
uzulla
25
6.4k
uniqueパッケージの内部実装を支えるweak pointerの話
magavel
0
1k
あなたとKaigi on Rails / Kaigi on Rails + You
shimoju
0
170
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
710
3年ぶりにコードを書いた元CTOが Claude Codeと30分でMVPを作った話
maikokojima
0
560
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
190
Featured
See All Featured
Thoughts on Productivity
jonyablonski
70
4.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
The Power of CSS Pseudo Elements
geoffreycrofte
79
6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.7k
The Language of Interfaces
destraynor
162
25k
Why Our Code Smells
bkeepers
PRO
340
57k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Producing Creativity
orderedlist
PRO
347
40k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
KATA
mclloyd
PRO
32
15k
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/