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
100
2
Share
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
98
Other Decks in Programming
See All in Programming
飯MCP
yusukebe
0
500
iOS機能開発のAI環境と起きた変化
ryunakayama
0
180
存在論的プログラミング: 時間と存在を記述する
koriym
5
870
TiDBのアーキテクチャから学ぶ分散システム入門 〜MySQL互換のNewSQLは何を解決するのか〜 / tidb-architecture-study
dznbk
1
160
Radical Imagining - LIFT 2025-2027 Policy Agenda
lift1998
0
280
KagglerがMixSeekを触ってみた
morim
0
380
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
370
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
200
実践CRDT
tamadeveloper
0
470
Java 21/25 Virtual Threads 소개
debop
0
350
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
400
PHPで TLSのプロトコルを実装してみるをもう一度しゃべりたい
higaki_program
0
200
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Navigating Weather and Climate Data
rabernat
0
160
The Curious Case for Waylosing
cassininazir
0
300
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Code Review Best Practice
trishagee
74
20k
Test your architecture with Archunit
thirion
1
2.2k
Are puppies a ranking factor?
jonoalderson
1
3.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Mobile First: as difficult as doing things right
swwweet
225
10k
Music & Morning Musume
bryan
47
7.1k
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/