SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
Buku Kecil
Tentang
Coffeescript
Widoyo, dari   http://arcturo.github.com/library/coffeescript/index.html
Pendahuluan
● Coffeescript adalah bahasa kecil yang
  dikompilasi menjadi javascript
● Inspirasi dari Ruby dan Python
● Lebih sedikit 'code' yang anda tulis
  dibanding dengan Javascript, sepertiga atau
  setengahnya
● Sebaiknya anda telah mengetahui javascript
● Install
  ○ Install nodejs (nodejs.org)
  ○ Install npm (npmjs.org)
  ○ npm install -g coffee-script
Syntax
● # komentar
● ###
      komentar
      banyak baris
  ###
● myVariable = "test"
● exports = this
  exports.myVariable = "foo-bar"
Syntax
● func = -> "bar"
● func = ->
    # harus indent spt Python
    "bar"
● kali = (a, b=2) -> a * b # argument
● jum = (nums...) ->
    # ... splats
    hasil = 0
    nums.forEach (n) -> result += n
    result
Syntax
● Eksekusi Fungsi
  a = "Hallo!"
  alert a
  alert(a) # sda

  alert inspect a
  alert(inspect(a)) # sda

  alert inspect(a) # disarankan
Object
● object1 = { satu: 1, dua: 2 }
● # tanpa {}
  object2 = satu: 1, dua: 2
● # menggunakan baris baru
  object3 =
    satu: 1
    dua: 2
Array
● array1 = [1, 2, 3]
● # multi baris
  array2 = [
    1
    2
    3
  ]
● array3 = [1, 2, 3,]
Flow Control
● if true == true
     "We're OK"
● if true != true then "Panic"
● # ekivalen dengan
  # (0 < 1) ? "Ok" : "NOk"
  if 0 < 1 then "Ok" else "NOk"
● alert "dingin!" if heat < 18
● unless true
     "panic"
● if true is 1 then "type fail"
String Interpolation
● kusuka = "hijau"
● pertanyaan = "Anton: apa warna
  kesu..
                 Jarwo: #{kusuka}
                 Anton: ya!
               "
Loop & Comprehension
● for nama in ["Zuki", "Barong",
  "Cel"]
    alert "#{nama}"
● for nama, i in ["Zuk", "Bar", "Cel"]
    alert "ke-#{i} adalah #{nama}"
● alert nama for nama in ["Zuk",
  "Bar"]
● for nama in ["Zuk", "Bar"] when nama
  [0] is "Z"
Alias & Existential
● @savior = true
  # @ alias untuk this.
● User::first = @records[0]
  # :: alias untuk prototype
● praise if brian?
  # ? meriksa existensi object dan
  bool
● velocity = southern ? 40
  # sekaligus meng ||
● mrPresident.getHands()?.tulis()
Class
● class Warga
● warga = new Warga
● class Warga
    constructor: (nama) ->
      @nama = nama
● class Warga
    constructor: (@nama) ->
● wargaBaru = new Warga("Widoyo")
  console.log "Warga baru adalah #
  {wargaBaru.nama}"
Instance Properties
● class Animal
    price: 5

    sell: (customer) ->
● animal = new Animal
● animal.sell(new Customer)
Instance Properties
● class Animal
    price: 5

    sell: =>
      alert "Give me #{price}"
● animal = new Animal
● $("#sell").click(animal.sell)
Static Properties
● class Warga
    this.find: (nama) ->
● # disingkat
  class Warga
    @find: (nama) ->
Inheritance & Super
● class Animal
    constructor: (@nama) ->

    alive: ->
      false
● class Parrot extends Animal
    constructor: ->
      super("Parrot")

    dead: -> not @alive()
Mixins

Más contenido relacionado

La actualidad más candente

Coding with Vim
Coding with VimCoding with Vim
Coding with VimEnzo Wang
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Toolschrismdp
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Puppet
 
An Introduction to WebWorker - 01.26.12
An Introduction to WebWorker - 01.26.12An Introduction to WebWorker - 01.26.12
An Introduction to WebWorker - 01.26.12Digiflare
 
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in RubyRubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in RubyRuby Bangladesh
 
Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発swdyh
 
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросыNikolay Samokhvalov
 
Travis CI+Dockerで複数バージョンの単体テスト
Travis CI+Dockerで複数バージョンの単体テストTravis CI+Dockerで複数バージョンの単体テスト
Travis CI+Dockerで複数バージョンの単体テストSho Hashimoto
 
Nomethoderror talk
Nomethoderror talkNomethoderror talk
Nomethoderror talkJan Berdajs
 
Intro oracle10gexpress
Intro oracle10gexpressIntro oracle10gexpress
Intro oracle10gexpressjatin Sareen
 
Library management system code
Library management system codeLibrary management system code
Library management system codeNaman Maheshwari
 

La actualidad más candente (13)

Coding with Vim
Coding with VimCoding with Vim
Coding with Vim
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Tools
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
 
Beware sharp tools
Beware sharp toolsBeware sharp tools
Beware sharp tools
 
An Introduction to WebWorker - 01.26.12
An Introduction to WebWorker - 01.26.12An Introduction to WebWorker - 01.26.12
An Introduction to WebWorker - 01.26.12
 
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in RubyRubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
 
Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発
 
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 
Travis CI+Dockerで複数バージョンの単体テスト
Travis CI+Dockerで複数バージョンの単体テストTravis CI+Dockerで複数バージョンの単体テスト
Travis CI+Dockerで複数バージョンの単体テスト
 
Nomethoderror talk
Nomethoderror talkNomethoderror talk
Nomethoderror talk
 
Intro oracle10gexpress
Intro oracle10gexpressIntro oracle10gexpress
Intro oracle10gexpress
 
Library management system code
Library management system codeLibrary management system code
Library management system code
 

Destacado

Masih m bajak software
Masih m bajak software  Masih m bajak software
Masih m bajak software Widoyo PH
 
Easy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & MercurialEasy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & MercurialWidoyo PH
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project ManagementWidoyo PH
 
Kewirausahaan
KewirausahaanKewirausahaan
KewirausahaanWidoyo PH
 
Langkah-langkah Membuat Software Aplikasi
Langkah-langkah Membuat Software AplikasiLangkah-langkah Membuat Software Aplikasi
Langkah-langkah Membuat Software AplikasiWidoyo PH
 
Source code management
Source code managementSource code management
Source code managementWidoyo PH
 
Python - Telegram
Python - TelegramPython - Telegram
Python - TelegramWidoyo PH
 

Destacado (7)

Masih m bajak software
Masih m bajak software  Masih m bajak software
Masih m bajak software
 
Easy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & MercurialEasy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & Mercurial
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project Management
 
Kewirausahaan
KewirausahaanKewirausahaan
Kewirausahaan
 
Langkah-langkah Membuat Software Aplikasi
Langkah-langkah Membuat Software AplikasiLangkah-langkah Membuat Software Aplikasi
Langkah-langkah Membuat Software Aplikasi
 
Source code management
Source code managementSource code management
Source code management
 
Python - Telegram
Python - TelegramPython - Telegram
Python - Telegram
 

Similar a Buku kecil coffee script

Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAhmed Salama
 
Ruby Basics by Rafiq
Ruby Basics by RafiqRuby Basics by Rafiq
Ruby Basics by RafiqRafiqdeen
 
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽tbosstraining
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Beautiful python - PyLadies
Beautiful python - PyLadiesBeautiful python - PyLadies
Beautiful python - PyLadiesAlicia Pérez
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parserkamaelian
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobikrmboya
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick touraztack
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on PythonSumit Raj
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real Worldosfameron
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deckMikeBegley
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutesSumit Raj
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05cKaz Yoshikawa
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text ProcessingRodrigo Senra
 
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuff
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuffHidden in Plain Sight: DUAL_EC_DRBG 'n stuff
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuffWhiskeyNeon
 

Similar a Buku kecil coffee script (20)

Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python 1
Python 1Python 1
Python 1
 
Ruby Basics by Rafiq
Ruby Basics by RafiqRuby Basics by Rafiq
Ruby Basics by Rafiq
 
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Beautiful python - PyLadies
Beautiful python - PyLadiesBeautiful python - PyLadies
Beautiful python - PyLadies
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parser
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deck
 
Functional python
Functional pythonFunctional python
Functional python
 
PythonIntro_pycon2010
PythonIntro_pycon2010PythonIntro_pycon2010
PythonIntro_pycon2010
 
Python
PythonPython
Python
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
 
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuff
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuffHidden in Plain Sight: DUAL_EC_DRBG 'n stuff
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuff
 

Buku kecil coffee script

  • 1. Buku Kecil Tentang Coffeescript Widoyo, dari http://arcturo.github.com/library/coffeescript/index.html
  • 2. Pendahuluan ● Coffeescript adalah bahasa kecil yang dikompilasi menjadi javascript ● Inspirasi dari Ruby dan Python ● Lebih sedikit 'code' yang anda tulis dibanding dengan Javascript, sepertiga atau setengahnya ● Sebaiknya anda telah mengetahui javascript ● Install ○ Install nodejs (nodejs.org) ○ Install npm (npmjs.org) ○ npm install -g coffee-script
  • 3. Syntax ● # komentar ● ### komentar banyak baris ### ● myVariable = "test" ● exports = this exports.myVariable = "foo-bar"
  • 4. Syntax ● func = -> "bar" ● func = -> # harus indent spt Python "bar" ● kali = (a, b=2) -> a * b # argument ● jum = (nums...) -> # ... splats hasil = 0 nums.forEach (n) -> result += n result
  • 5. Syntax ● Eksekusi Fungsi a = "Hallo!" alert a alert(a) # sda alert inspect a alert(inspect(a)) # sda alert inspect(a) # disarankan
  • 6. Object ● object1 = { satu: 1, dua: 2 } ● # tanpa {} object2 = satu: 1, dua: 2 ● # menggunakan baris baru object3 = satu: 1 dua: 2
  • 7. Array ● array1 = [1, 2, 3] ● # multi baris array2 = [ 1 2 3 ] ● array3 = [1, 2, 3,]
  • 8. Flow Control ● if true == true "We're OK" ● if true != true then "Panic" ● # ekivalen dengan # (0 < 1) ? "Ok" : "NOk" if 0 < 1 then "Ok" else "NOk" ● alert "dingin!" if heat < 18 ● unless true "panic" ● if true is 1 then "type fail"
  • 9. String Interpolation ● kusuka = "hijau" ● pertanyaan = "Anton: apa warna kesu.. Jarwo: #{kusuka} Anton: ya! "
  • 10. Loop & Comprehension ● for nama in ["Zuki", "Barong", "Cel"] alert "#{nama}" ● for nama, i in ["Zuk", "Bar", "Cel"] alert "ke-#{i} adalah #{nama}" ● alert nama for nama in ["Zuk", "Bar"] ● for nama in ["Zuk", "Bar"] when nama [0] is "Z"
  • 11. Alias & Existential ● @savior = true # @ alias untuk this. ● User::first = @records[0] # :: alias untuk prototype ● praise if brian? # ? meriksa existensi object dan bool ● velocity = southern ? 40 # sekaligus meng || ● mrPresident.getHands()?.tulis()
  • 12. Class ● class Warga ● warga = new Warga ● class Warga constructor: (nama) -> @nama = nama ● class Warga constructor: (@nama) -> ● wargaBaru = new Warga("Widoyo") console.log "Warga baru adalah # {wargaBaru.nama}"
  • 13. Instance Properties ● class Animal price: 5 sell: (customer) -> ● animal = new Animal ● animal.sell(new Customer)
  • 14. Instance Properties ● class Animal price: 5 sell: => alert "Give me #{price}" ● animal = new Animal ● $("#sell").click(animal.sell)
  • 15. Static Properties ● class Warga this.find: (nama) -> ● # disingkat class Warga @find: (nama) ->
  • 16. Inheritance & Super ● class Animal constructor: (@nama) -> alive: -> false ● class Parrot extends Animal constructor: -> super("Parrot") dead: -> not @alive()