SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante 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
 

Semelhante 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
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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, ...
 
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
 
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
 

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