SlideShare uma empresa Scribd logo
1 de 34
COFFEESCRIPT:
JAVASCRIPT, BUT
    BETTER
WHO AM I?
www.jackfranklin.co.uk

   @Jack_Franklin
COFFEESCRIPT:
JAVASCRIPT, BUT
    BETTER
GOLDEN RULE OF COFFEESCRIPT
      “it’s just javascript”
IN BRIEF, COFFEESCRIPT:
1. COMPILES INTO REGULAR JAVASCRIPT
2. SOLVES A LOT OF COMMON ISSUES & GRIPES
3. MAKES JAVASCRIPT QUICKER & EASIER TO
WRITE
4. IS JUST JAVASCRIPT
JAVASCRIPT:
$(“a”).click(function() {
    alert(“hi”);
});
COFFEESCRIPT:
$(“a”).click ->
   alert “hi”
DIFFERENCES:
1. INDENTATION MATTERS (NO { } NEEDED)
2. SEMI-COLONS NOT REQUIRED
3. NO PARENTHESIS AROUND ARGUMENTS
4. function() BECOMES ->
THREE EASY STEPS:
1. WRITE CODE IN .COFFEE FILE
2. COMPILE TO .JS (AND FIX ERRORS)
3. INCLUDE .JS FILE IN WEBSITE
COMPILING
1. INSTALL NODE.JS
2. INSTALL NPM (NODE PACKAGE MANAGER)
3. npm install -g coffee-script
4. coffee --watch --compile
example.coffee
IF TERMINAL SCARES YOU
1. WINDOWS:
https://github.com/alisey/CoffeeScript-
Compiler-for-Windows
2. MAC OS X: http://livereload.com/
COFFEESCRIPT
  FEATURES
NO VAR:
a=2
#compiles to:
var a;
a = 2;
CODE IS PRIVATE:
(function() {
    /*your code goes here*/
}).call(this);
GETS RID OF == & ===
          CONFUSION
“true” == true //true
“true” === true //false


                 ( WTF? )
GETS RID OF == & ===
           CONFUSION
“true” is true //false
“true” is “true” //true
launch() if ignition is on

volume = 10 if band isnt SpinalTap

letTheWildRumpusBegin() unless answer is no

if car.speed < limit then accelerate()

winner = yes if pick in [47, 92, 13]
is <=> ===
isnt <=> !==
not <=> !
and <=> &&
or <=> ||
true, yes, on <=> true
false, no, off <=> false
@, this <=> this
of <=> in
in <=> //no JS equiv
#in tests for array presence
#of tests for object-key presence

(
in tests for array presence


of tests for object-key presence
BASIC FUNCTION SYNTAX
function heyBarcamp(m) {
    alert(“Hey Barcamp! “ + m);
});
BASIC FUNCTION SYNTAX
heyBarcamp = (m) ->
  alert “Hey BarCamp! “ + m
COMMENTING
#this is a comment
###
  block comment!
  OMG!
###
PLAYS NICE WITH LIBRARIES
          (it’s just JavaScript, remember)

$(function() {
    $(“body”).html(“HEY BARCAMP”);
});
PLAYS NICE WITH LIBRARIES
         (it’s just JavaScript, remember)

$ ->
   $(“body”).html “HEY BARCAMPERS”
LOVELY ITERATION
for attendee in barcampers when attendee.age
< 16
   console.log “CHILD! “ + attendee.name
LOVELY ITERATION
tweets.push(
   tweet.text.toLowerCase()
) for tweet in data
CLASSES
class Presentation
   constructor (room) ->
      @room = room
   startPresentation ->
      @loadSlideShow()
   loadSlideShow ->

quiz = new Presentation “Pan’s Labyrinth”
CONDITIONALS
someFunc() if y > 20
x = 2 unless y > 10
currentUrl ?= window.location
SPLIT ASSIGNMENT
//regular JavaScript:
var myName = [“Jack”, “Franklin”];
var firstName = myName[0],
   surName = myName[1];
//CoffeeScript:
myName = [“Jack”, “Franklin”]
[firstName, surName] = myName
VARIABLES IN STRINGS
heyBarcamp = (message) ->
   alert “Hello BarCampers! I’ve got a message
for you #{message}”
VARIABLES IN STRINGS
heyBarcamp = (message) ->
   alert “Hello BarCampers! I’ve got a message
for you #{message.toUpperCase()}”
DEFAULT FUNCTION VALUES
addNumbers = (a, b = 2) ->
  alert a+b
WE’VE ONLY SCRATCHED THE
SURFACE!
1. DOCS & ONLINE SHELL ON GITHUB:
http://jashkenas.github.com/coffee-script/
2. FUN FACT: COFFEESCRIPT COMPILER WAS
WRITTEN IN COFFEESCRIPT
THANKS FOR LISTENING...ANY
   (EASY) QUESTIONS?

@JACK_FRANKLIN

Mais conteúdo relacionado

Mais procurados

php drupal mysql MAMP
php drupal mysql MAMPphp drupal mysql MAMP
php drupal mysql MAMP
Jing Cheng
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
Nobuo Danjou
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
Lukas Lesniewski
 

Mais procurados (20)

Zeppelin Helium: Spell
Zeppelin Helium: SpellZeppelin Helium: Spell
Zeppelin Helium: Spell
 
Knee-deep in C++ s... code
Knee-deep in C++ s... codeKnee-deep in C++ s... code
Knee-deep in C++ s... code
 
톰캣 #04-환경설정
톰캣 #04-환경설정톰캣 #04-환경설정
톰캣 #04-환경설정
 
関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード
 
PHP 7.x - past, present, future (WordPress Varna #4)
PHP 7.x - past, present, future (WordPress Varna #4)PHP 7.x - past, present, future (WordPress Varna #4)
PHP 7.x - past, present, future (WordPress Varna #4)
 
East Bay Ruby Tropo presentation
East Bay Ruby Tropo presentationEast Bay Ruby Tropo presentation
East Bay Ruby Tropo presentation
 
Zen: Building Maintainable Catalyst Applications
Zen: Building Maintainable Catalyst ApplicationsZen: Building Maintainable Catalyst Applications
Zen: Building Maintainable Catalyst Applications
 
[DevDay2018] How does JavaScript actually work? - By: Vi Nguyen, Senior Softw...
[DevDay2018] How does JavaScript actually work? - By: Vi Nguyen, Senior Softw...[DevDay2018] How does JavaScript actually work? - By: Vi Nguyen, Senior Softw...
[DevDay2018] How does JavaScript actually work? - By: Vi Nguyen, Senior Softw...
 
次世代PHPフレームワーク Symfony2
次世代PHPフレームワーク Symfony2次世代PHPフレームワーク Symfony2
次世代PHPフレームワーク Symfony2
 
php drupal mysql MAMP
php drupal mysql MAMPphp drupal mysql MAMP
php drupal mysql MAMP
 
2010/7/31 LTの虎@LL Tiger
2010/7/31 LTの虎@LL Tiger2010/7/31 LTの虎@LL Tiger
2010/7/31 LTの虎@LL Tiger
 
21.search in laravel
21.search in laravel21.search in laravel
21.search in laravel
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
 
Introduction to Perl Programming
Introduction to Perl ProgrammingIntroduction to Perl Programming
Introduction to Perl Programming
 
Deixe o teste infectar você
Deixe o teste infectar vocêDeixe o teste infectar você
Deixe o teste infectar você
 
[Erlang LT] Regexp Perl And Port
[Erlang LT] Regexp Perl And Port[Erlang LT] Regexp Perl And Port
[Erlang LT] Regexp Perl And Port
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
 
Exceptions in PHP
Exceptions in PHPExceptions in PHP
Exceptions in PHP
 
Debugging in Clojure: Finding Light in the Darkness using Emacs and Cursive
Debugging in Clojure: Finding Light in the Darkness using Emacs and CursiveDebugging in Clojure: Finding Light in the Darkness using Emacs and Cursive
Debugging in Clojure: Finding Light in the Darkness using Emacs and Cursive
 
A piece of sugar in your client-side development
A piece of sugar in your client-side developmentA piece of sugar in your client-side development
A piece of sugar in your client-side development
 

Destaque (6)

Java script
Java scriptJava script
Java script
 
jQuery Tips & Tricks - Bath Camp 2010
jQuery Tips & Tricks - Bath Camp 2010jQuery Tips & Tricks - Bath Camp 2010
jQuery Tips & Tricks - Bath Camp 2010
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
Introduction to jQuery at Barcamp London 8
Introduction to jQuery at Barcamp London 8Introduction to jQuery at Barcamp London 8
Introduction to jQuery at Barcamp London 8
 
Designing for the Teenage Market
Designing for the Teenage MarketDesigning for the Teenage Market
Designing for the Teenage Market
 
How do we prepare vocational teachers for the demands of the digital world
How do we prepare vocational teachers for the demands of the digital worldHow do we prepare vocational teachers for the demands of the digital world
How do we prepare vocational teachers for the demands of the digital world
 

Semelhante a CoffeeScript: JavaScript, but Better!

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
jhchabran
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
Eddie Kao
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developers
Mehdi Valikhani
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
Chris Saylor
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Semelhante a CoffeeScript: JavaScript, but Better! (20)

5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
CoffeeScript - en introduksjon
CoffeeScript - en introduksjonCoffeeScript - en introduksjon
CoffeeScript - en introduksjon
 
Coffeescript slides
Coffeescript slidesCoffeescript slides
Coffeescript slides
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Quick coffeescript
Quick coffeescriptQuick coffeescript
Quick coffeescript
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developers
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with Yield
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Java script for web developer
Java script for web developerJava script for web developer
Java script for web developer
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

CoffeeScript: JavaScript, but Better!

Notas do Editor

  1. \n
  2. student &amp; developer\n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. nodejs.org\nnpmjs.org\n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n