6-1-class.coffee 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. class Coffee0
  2. constructor: (name, strength = 1) ->
  3. @name = name
  4. @strength = strength
  5. class Coffee
  6. constructor: (@name, @strength = 1) ->
  7. brew: -> alert "brewing #{@name}"
  8. pour: (amount = 1) ->
  9. if amount is 1
  10. "Poured a single cup"
  11. else
  12. "Poured #{amount} cups"
  13. french = new Coffee("French", 2)
  14. french.brew()
  15. alert(french.pour())
  16. alert(french.pour(2))
  17. class MaxgoodHouse extends Coffee
  18. # Cannot use @param format, because of the required call to super in Coffee 2.x.
  19. constructor: (name, strength = 0) ->
  20. super name, strength
  21. @name = name
  22. @strength = strength
  23. @brand = "Maxgood House"
  24. pour: (amount = 1) ->
  25. "#{super(amount)}, but it sucks"
  26. boring = new MaxgoodHouse("Boring")
  27. boring.brew()
  28. alert(boring.pour())
  29. class JCoffee
  30. constructor: (@name, @strength = 1, @inventory = 0) ->
  31. pourClick: ->
  32. $("#pour-#{@name}").click (event) =>
  33. if @inventory != 0
  34. @inventory--
  35. alert "Poured a cup of #{@name}"
  36. else
  37. alert "Out of #{@name}"
  38. j = new JCoffee "French", 2, 1
  39. j.pourClick()
  40. class SelectFlights
  41. constructor(@fetchingFlights = null) ->
  42. $("#tabs ul li a").bind
  43. click: @changeTab
  44. $("#tabs #error a").click (event) =>
  45. event.preventDefault()
  46. @showFlights $("#tabs li a.active").attr("href")
  47. showFlights: (activeDiv) -> {}
  48. changeTab: (event) => {}