Much Ado About
   CoffeeScript

Mattt Thompson (@mattt)
Lone Star Ruby Conf V
Sass
CoffeeScript
Sass                 →         CSS
$blue: #3bbfce                   .content-navigation {
$margin: 16px                      border-color: #3bbfce;
                                   color: #2ca2af; }
.content-navigation
  border-color: $blue            .border {
  color: darken($blue, 9%)         padding: 8px;
                                   margin: 8px;
.border                            border-color: #3bbfce; }
  padding: $margin / 2
  margin: $margin / 2
  border-color: $blue
CoffeeScript                   →        JavaScript
                                    var Account;
Account = (customer, cart) ->       var __bind = function(fn, me)
  @customer = customer              { return function(){ return
  @cart = cart                      fn.apply(me, arguments); }; };
                                    Account = function(customer, cart)
                                    {
  $('.shopping_cart').bind ↩           this.customer = customer;
'click', (event) =>                    this.cart = cart;
                                       return $
    @customer.purchase @cart        ('.shopping_cart').bind('click',
                                    __bind(function(event) {
                                         return
                                    this.customer.purchase(this.cart);
                                       }, this));
                                    };
CoffeeScript
“It’s just Javascript”
• Less Syntactic Cruft
• JavaScript Design Patterns
  are Features of
  CoffeeScript
"Coffee Script" in Brief
"Coffee Script" in Brief
Syntax
jQuery(function() {
  $("#title").show();
});
jQuery function()
  $("#title").show()
jQuery ->
  $("#title").show()
Store.prototype.add = function(item) {
  this.items.push(item);
}
Store.prototype.add = function(item)
  this.items.push(item)
Store.prototype.add = function(item)
  @items.push(item)
add: function(item)
  @items.push(item)
add: ->      (item)
  @items.push(item)
add: (item) ->
  @items.push(item)
• Redundant Punctuation Omitted
• function becomes ->

• this. becomes @

• {} becomes ⇥
Features
"Coffee Script" in Brief
"Coffee Script" in Brief
1
Class Pattern
class Animal
  constructor: (name) ->
    @name = name
var Animal;
Animal = (function() {
  function Animal(name) {
    this.name = name;
  }
  return Animal;
})();
2
Lexical Scoping
(No Global Variables)
window.Animal = class Animal
  constructor: (name) ->
    @name = name
3
Default Arguments
window.Animal = class Animal
  constructor: (name = "Unknown") ->
    @name = name
4
String Interpolation
class Bear extends Animal
  constructor: (name) ->
    @name = "#{name}, the Bear"
5
Conditional Suffixes
@price = amount if amount > 0.00
6
Operator Aliases
@lovesTacos = false unless @name is "Mattt"
CoffeeScript    JavaScript
     is            ===
    isnt           !==
    not             !
    and            &&
     or            ||
true, yes, on     true
  @, this         this
     of            in
     in            N/A
7
Deconstructing
 Assignment
[dollars, cents] = input.match /(d+)/g
8
Existential Operator
?
[dollars, cents] = (input.match /(d+)/g) ? [0, 0]
9
Splats
gold, silver, bronze, rest = ""

awardMedals = (first, second, third, others...) ->
  gold   = first
  silver = second
  bronze = third
  rest   = others

pieEatingCompetitors = [
  "Wynn Netherland",
  "Steve Klabnik",
  "Adam Keys",
  "Richard Schneeman",
  "Rob Mack",
  "Tim Tyrrell",
  "Steve Stedman",
  "Mando Escamilla",
  "Keith Gaddis"
]

awardMedals pieEatingCompetitors...
10
List Comprehensions
eat food for food in ['toast', 'cheese', 'wine']
eat food for food in ['toast', 'cheese', 'wine'] ↩
  when food is "toast"
languages = {
  "Javascript": 3,
  "CoffeeScript": 9,
  "Ruby": 9,
  "Python": 6,
  "Objective-C": 7,
  "Potion": 10
}

favorites = language for language, awesomeness of ↩
  languages when awesomeness >= 7
"Coffee Script" in Brief

More Related Content

PDF
Desarrollo de módulos en Drupal e integración con dispositivos móviles
PPTX
Jquery optimization-tips
PDF
Growing jQuery
PPT
Kick start with j query
PPTX
JavaScript Objects and OOP Programming with JavaScript
KEY
Phpで作るmovable typeプラグイン
PPTX
Jquery plugin development
PDF
Transparent Object Persistence with FLOW3
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Jquery optimization-tips
Growing jQuery
Kick start with j query
JavaScript Objects and OOP Programming with JavaScript
Phpで作るmovable typeプラグイン
Jquery plugin development
Transparent Object Persistence with FLOW3

What's hot (20)

PDF
The jQuery Divide
PDF
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
KEY
Zf Zend Db by aida
PDF
Learning jQuery in 30 minutes
PDF
Functionality Focused Code Organization
PDF
Command-Oriented Architecture
PDF
Prototype & jQuery
PPTX
Fact, Fiction, and FP
KEY
JQuery In Rails
PDF
PhoneGap: Local Storage
PPTX
Mootools selectors
KEY
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
PDF
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
PPTX
PDF
Jquery In Rails
PPTX
Taming that client side mess with Backbone.js
ODP
Introduction to jQuery
PDF
Drupal, meet Assetic
PDF
Add edit delete in Codeigniter in PHP
PDF
Modern Application Foundations: Underscore and Twitter Bootstrap
The jQuery Divide
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Zf Zend Db by aida
Learning jQuery in 30 minutes
Functionality Focused Code Organization
Command-Oriented Architecture
Prototype & jQuery
Fact, Fiction, and FP
JQuery In Rails
PhoneGap: Local Storage
Mootools selectors
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Jquery In Rails
Taming that client side mess with Backbone.js
Introduction to jQuery
Drupal, meet Assetic
Add edit delete in Codeigniter in PHP
Modern Application Foundations: Underscore and Twitter Bootstrap
Ad

Viewers also liked (8)

PPT
Community-generated Traffic Information System
PDF
Raspberry pi meetup Bangkok
KEY
Facebook OD
PPTX
Community-generated Traffic Information System(PPTX)
PDF
Gdg wednesday
PDF
Booklat @ Social Innovation Camp Asia 2013 (SICA2013)
KEY
Grade Thammasat University
PPTX
Griffon Topic2 Presentation (Tia)
Community-generated Traffic Information System
Raspberry pi meetup Bangkok
Facebook OD
Community-generated Traffic Information System(PPTX)
Gdg wednesday
Booklat @ Social Innovation Camp Asia 2013 (SICA2013)
Grade Thammasat University
Griffon Topic2 Presentation (Tia)
Ad

Similar to "Coffee Script" in Brief (20)

KEY
Introduction à CoffeeScript pour ParisRB
PDF
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
PDF
Your code sucks, let's fix it - DPC UnCon
PPTX
PDF
Damn Fine CoffeeScript
PDF
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
PPTX
Tidy Up Your Code
PDF
Min-Maxing Software Costs
PDF
jQuery - 10 Time-Savers You (Maybe) Don't Know
PDF
Command Bus To Awesome Town
PDF
The Art of Transduction
PDF
PHPSpec - the only Design Tool you need - 4Developers
PDF
10...ish things i learned from programming an e-shop for a year
PDF
Taming Command Bus
PDF
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
PDF
You code sucks, let's fix it
PDF
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PDF
Bag Of Tricks From Iusethis
PDF
laravel tricks in 50minutes
PDF
50 Laravel Tricks in 50 Minutes
Introduction à CoffeeScript pour ParisRB
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Your code sucks, let's fix it - DPC UnCon
Damn Fine CoffeeScript
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Tidy Up Your Code
Min-Maxing Software Costs
jQuery - 10 Time-Savers You (Maybe) Don't Know
Command Bus To Awesome Town
The Art of Transduction
PHPSpec - the only Design Tool you need - 4Developers
10...ish things i learned from programming an e-shop for a year
Taming Command Bus
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
You code sucks, let's fix it
PHPCon 2016: PHP7 by Witek Adamus / XSolve
Bag Of Tricks From Iusethis
laravel tricks in 50minutes
50 Laravel Tricks in 50 Minutes

More from Nat Weerawan (20)

PDF
MLBlock
PDF
CMMC IoT & MQTT
PDF
KidBright Plugin development
PDF
Kidbright plugin development
PDF
ESPNow Again..
PDF
CMMC - IoT
PDF
CMMC - CNX - Community of Practice 1
PDF
Chiang Mai Maker Club & Thailand 4.0
PDF
What is Chiang Mai Maker Club - BRIEF
PDF
Create connected home devices using a Raspberry Pi, Siri and ESPNow for makers.
PDF
Chaing Mai Maker Club @Creative Thailand Symposium
PDF
Netpie.io Generate MQTT Credential
PDF
IBM Bluemix & IoT Foundation
PDF
CMMC - Chiang Mai Maker Club
PDF
Link it smart 7688 MEETUP - Bangkok
PDF
LoveNotYet - The first Thailand sex education game.
PDF
Raspberry Pi @ Beercamp Chiangmai
KEY
Install Installous On iPod Touch
KEY
Indexing Present1
KEY
GettingStartedWithPHP
MLBlock
CMMC IoT & MQTT
KidBright Plugin development
Kidbright plugin development
ESPNow Again..
CMMC - IoT
CMMC - CNX - Community of Practice 1
Chiang Mai Maker Club & Thailand 4.0
What is Chiang Mai Maker Club - BRIEF
Create connected home devices using a Raspberry Pi, Siri and ESPNow for makers.
Chaing Mai Maker Club @Creative Thailand Symposium
Netpie.io Generate MQTT Credential
IBM Bluemix & IoT Foundation
CMMC - Chiang Mai Maker Club
Link it smart 7688 MEETUP - Bangkok
LoveNotYet - The first Thailand sex education game.
Raspberry Pi @ Beercamp Chiangmai
Install Installous On iPod Touch
Indexing Present1
GettingStartedWithPHP

Recently uploaded (20)

PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPT
What is a Computer? Input Devices /output devices
PDF
August Patch Tuesday
PDF
Architecture types and enterprise applications.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PPTX
The various Industrial Revolutions .pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
CloudStack 4.21: First Look Webinar slides
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Five Habits of High-Impact Board Members
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
What is a Computer? Input Devices /output devices
August Patch Tuesday
Architecture types and enterprise applications.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
Taming the Chaos: How to Turn Unstructured Data into Decisions
The various Industrial Revolutions .pptx
Chapter 5: Probability Theory and Statistics
A comparative study of natural language inference in Swahili using monolingua...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
observCloud-Native Containerability and monitoring.pptx
O2C Customer Invoices to Receipt V15A.pptx
Tartificialntelligence_presentation.pptx
CloudStack 4.21: First Look Webinar slides
A novel scalable deep ensemble learning framework for big data classification...
A contest of sentiment analysis: k-nearest neighbor versus neural network
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Five Habits of High-Impact Board Members

"Coffee Script" in Brief