Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Much Ado About CoffeeScript

Much Ado About CoffeeScript

CoffeeScript will ship with Rails 3.1 to replace RJS as the preferred way to dynamically generate JavaScript. It's a new language that take the best parts of Ruby, Python, and others to ease the worst parts of JavaScript. More than being the new kid on the Rails block however, CoffeeScript is mind-expanding in ways that will make you remember the first time you ever gave Ruby a try. This presentation will take you through the basics of CoffeeScript, starting with a crash course in syntax, all the way to a working application.

Mattt Thompson

September 22, 2011
Tweet

More Decks by Mattt Thompson

Other Decks in Programming

Transcript

  1. 3.1

  2. Sass → CSS $blue: #3bbfce $margin: 16px .content-navigation border-color: $blue

    color: darken($blue, 9%) .border padding: $margin / 2 margin: $margin / 2 border-color: $blue .content-navigation { border-color: #3bbfce; color: #2ca2af; } .border { padding: 8px; margin: 8px; border-color: #3bbfce; }
  3. CoffeeScript → JavaScript Account = (customer, cart) -> @customer =

    customer @cart = cart $('.shopping_cart').bind ↩ 'click', (event) => @customer.purchase @cart var Account; var __bind = function(fn, me) { return function(){ return fn.apply(me, arguments); }; }; Account = function(customer, cart) { this.customer = customer; this.cart = cart; return $ ('.shopping_cart').bind('click', __bind(function(event) { return this.customer.purchase(this.cart); }, this)); };
  4. • Installation • Integration With Rails • Syntax • Features

    Introducing CoffeeScript What We’ll Cover
  5. CoffeeScript JavaScript is === isnt !== not ! and &&

    or || true, yes, on true @, this this of in in N/A
  6. ?

  7. 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...
  8. languages = { "Javascript": 3, "CoffeeScript": 9, "Ruby": 9, "Python":

    6, "Objective-C": 7, "Potion": 10 } favorites = language for language, awesomeness of ↩ languages when awesomeness >= 7
  9. • Installation • Integration With Rails • Syntax • Features

    Introducing CoffeeScript What We’ve Covered So Far
  10. 2007 Ruby Era of competing Ruby implementations (MRI, YARV, Rubinius,

    JRuby) JavaScript Era of competing JavaScript frameworks (Prototype, jQuery, dojo, MooTools, YUI)