Buku KecilTentangCoffeescriptWidoyo, dari   http://arcturo.github.com/library/coffeescript/index.html
Pendahuluan● Coffeescript adalah bahasa kecil yang  dikompilasi menjadi javascript● Inspirasi dari Ruby dan Python● Lebih ...
Syntax● # komentar● ###      komentar      banyak baris  ###● myVariable = "test"● exports = this  exports.myVariable = "f...
Syntax● func = -> "bar"● func = ->    # harus indent spt Python    "bar"● kali = (a, b=2) -> a * b # argument● jum = (nums...
Syntax● Eksekusi Fungsi  a = "Hallo!"  alert a  alert(a) # sda  alert inspect a  alert(inspect(a)) # sda  alert inspect(a)...
Object● object1 = { satu: 1, dua: 2 }● # tanpa {}  object2 = satu: 1, dua: 2● # menggunakan baris baru  object3 =    satu:...
Array● array1 = [1, 2, 3]● # multi baris  array2 = [    1    2    3  ]● array3 = [1, 2, 3,]
Flow Control● if true == true     "Were OK"● if true != true then "Panic"● # ekivalen dengan  # (0 < 1) ? "Ok" : "NOk"  if...
String Interpolation● kusuka = "hijau"● pertanyaan = "Anton: apa warna  kesu..                 Jarwo: #{kusuka}           ...
Loop & Comprehension● for nama in ["Zuki", "Barong",  "Cel"]    alert "#{nama}"● for nama, i in ["Zuk", "Bar", "Cel"]    a...
Alias & Existential● @savior = true  # @ alias untuk this.● User::first = @records[0]  # :: alias untuk prototype● praise ...
Class● class Warga● warga = new Warga● class Warga    constructor: (nama) ->      @nama = nama● class Warga    constructor...
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").c...
Static Properties● class Warga    this.find: (nama) ->● # disingkat  class Warga    @find: (nama) ->
Inheritance & Super● class Animal    constructor: (@nama) ->    alive: ->      false● class Parrot extends Animal    const...
Mixins
Upcoming SlideShare
Loading in …5
×

Buku kecil coffee script

595 views
468 views

Published on

Dengan Coffeescript pemrograman menjadi lebih pendek, mencegah hal-hal yang tidak biasa (menyusahkan) pada Javascript.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
595
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Buku kecil coffee script

  1. 1. Buku KecilTentangCoffeescriptWidoyo, dari http://arcturo.github.com/library/coffeescript/index.html
  2. 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. 3. Syntax● # komentar● ### komentar banyak baris ###● myVariable = "test"● exports = this exports.myVariable = "foo-bar"
  4. 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. 5. Syntax● Eksekusi Fungsi a = "Hallo!" alert a alert(a) # sda alert inspect a alert(inspect(a)) # sda alert inspect(a) # disarankan
  6. 6. Object● object1 = { satu: 1, dua: 2 }● # tanpa {} object2 = satu: 1, dua: 2● # menggunakan baris baru object3 = satu: 1 dua: 2
  7. 7. Array● array1 = [1, 2, 3]● # multi baris array2 = [ 1 2 3 ]● array3 = [1, 2, 3,]
  8. 8. Flow Control● if true == true "Were 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. 9. String Interpolation● kusuka = "hijau"● pertanyaan = "Anton: apa warna kesu.. Jarwo: #{kusuka} Anton: ya! "
  10. 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. 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. 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. 13. Instance Properties● class Animal price: 5 sell: (customer) ->● animal = new Animal● animal.sell(new Customer)
  14. 14. Instance Properties● class Animal price: 5 sell: => alert "Give me #{price}"● animal = new Animal● $("#sell").click(animal.sell)
  15. 15. Static Properties● class Warga this.find: (nama) ->● # disingkat class Warga @find: (nama) ->
  16. 16. Inheritance & Super● class Animal constructor: (@nama) -> alive: -> false● class Parrot extends Animal constructor: -> super("Parrot") dead: -> not @alive()
  17. 17. Mixins

×