SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
CoffeeScript
JavaScript in a simple way


    Open Tech Talk – 22 Jan 2011
         @HackerSpacePP
           @lchanmann
CoffeeScript
●
    One-to-one with JavaScript
●
    Better functional syntax
●
    Compiles to the good parts
Why CoffeeScript?
●
    Less code
●
    Readability
●
    Easy to understand, and maintain
●
    But … you should know how JavaScript's
    concept work
JavaScript
CoffeeScript
JavaScript
Coffee
JavaScript
CoffeeScript
Functions



square = (x) -> x * x

area = (x, y) -> x * y

cube = (x) -> x * square x
Objects


                        kids = {
                           brother: {
kids =
                              name: "Max",
  brother:

                   >>
                              age: 11
    name: "Max"
                           },
    age: 11
                           sister: {
  sister:
                              name: "Ida",
    name: "Ida"
                              age: 9
    age: 9
                           }
                        };
Lexical Scoping / Variable Safety


                        (function() {
                          var change, inner, outer;
                          outer = 1;
outer = 1

                   >>
                          change = function() {
change = ->
                             var inner;
  inner = -1
                             inner = -1;
  outer = 10
                             return (outer = 10);
inner = change()
                          };
                          inner = change();
                        }).call(this);
Splats...



gold = silver = rest = "unknown"

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

class Animal
  constructor: (@name) ->

 move: (meters) ->
   alert @name + " moved " + meters + "m."

class Snake extends Animal
  move: ->
    alert "Slithering..."
    super 5

sam = new Snake "Sammy the Python"
sam.move()
The Rest...
✔   Existential operator
✔   Pattern matching with object literals
✔   Switch/When/Else
✔   Chained comparison
✔   Array comprehension
✔   Array slicing and splicing with ranges
✔   Everything is an expression; always a return value
✔   Function binding syntactical sugar
✔   String and RegExp Interpolation
✔   Multiline Strings, Heredocs, and Block Comments
✔   "text/coffeescript" script tags with extras/coffee-script.js
✔   It's just JavaScript
Last but not lease
●
    http://ryan.mcgeary.org/talks/2010/10/21/coffeescript-novarug/
●
    http://www.slideshare.net/mtaberski/coffee-script-6089214


●
    http://jashkenas.github.com/coffee-script/
Lim Chanmann


http://chanmannlim.wordpress.com/
           @lchanmann
      chanmannlim@gmail.com




           InSTEDD

Más contenido relacionado

Similar a CoffeeScript - JavaScript in a simple way

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
Joe Zulli
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Anton Shemerey
 

Similar a CoffeeScript - JavaScript in a simple way (20)

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
FITC CoffeeScript 101
FITC CoffeeScript 101FITC CoffeeScript 101
FITC CoffeeScript 101
 
Beginning Python
Beginning PythonBeginning Python
Beginning Python
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
 
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
 
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
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

CoffeeScript - JavaScript in a simple way

  • 1. CoffeeScript JavaScript in a simple way Open Tech Talk – 22 Jan 2011 @HackerSpacePP @lchanmann
  • 2. CoffeeScript ● One-to-one with JavaScript ● Better functional syntax ● Compiles to the good parts
  • 3. Why CoffeeScript? ● Less code ● Readability ● Easy to understand, and maintain ● But … you should know how JavaScript's concept work
  • 10. Functions square = (x) -> x * x area = (x, y) -> x * y cube = (x) -> x * square x
  • 11. Objects kids = { brother: { kids = name: "Max", brother: >> age: 11 name: "Max" }, age: 11 sister: { sister: name: "Ida", name: "Ida" age: 9 age: 9 } };
  • 12. Lexical Scoping / Variable Safety (function() { var change, inner, outer; outer = 1; outer = 1 >> change = function() { change = -> var inner; inner = -1 inner = -1; outer = 10 return (outer = 10); inner = change() }; inner = change(); }).call(this);
  • 13. Splats... gold = silver = rest = "unknown" awardMedals = (first, second, others...) -> gold = first silver = second rest = others
  • 14. OOP class Animal constructor: (@name) -> move: (meters) -> alert @name + " moved " + meters + "m." class Snake extends Animal move: -> alert "Slithering..." super 5 sam = new Snake "Sammy the Python" sam.move()
  • 15. The Rest... ✔ Existential operator ✔ Pattern matching with object literals ✔ Switch/When/Else ✔ Chained comparison ✔ Array comprehension ✔ Array slicing and splicing with ranges ✔ Everything is an expression; always a return value ✔ Function binding syntactical sugar ✔ String and RegExp Interpolation ✔ Multiline Strings, Heredocs, and Block Comments ✔ "text/coffeescript" script tags with extras/coffee-script.js ✔ It's just JavaScript
  • 16. Last but not lease ● http://ryan.mcgeary.org/talks/2010/10/21/coffeescript-novarug/ ● http://www.slideshare.net/mtaberski/coffee-script-6089214 ● http://jashkenas.github.com/coffee-script/
  • 17. Lim Chanmann http://chanmannlim.wordpress.com/ @lchanmann chanmannlim@gmail.com InSTEDD