6-1-class.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. var Coffee, Coffee0, JCoffee, MaxgoodHouse, SelectFlights, boring, french, j;
  2. Coffee0 = class Coffee0 {
  3. constructor(name, strength = 1) {
  4. this.name = name;
  5. this.strength = strength;
  6. }
  7. };
  8. Coffee = class Coffee {
  9. constructor(name1, strength1 = 1) {
  10. this.name = name1;
  11. this.strength = strength1;
  12. }
  13. brew() {
  14. return alert(`brewing ${this.name}`);
  15. }
  16. pour(amount = 1) {
  17. if (amount === 1) {
  18. return "Poured a single cup";
  19. } else {
  20. return `Poured ${amount} cups`;
  21. }
  22. }
  23. };
  24. french = new Coffee("French", 2);
  25. french.brew();
  26. alert(french.pour());
  27. alert(french.pour(2));
  28. MaxgoodHouse = class MaxgoodHouse extends Coffee {
  29. // Cannot use @param format, because of the required call to super in Coffee 2.x.
  30. constructor(name, strength = 0) {
  31. super(name, strength);
  32. this.name = name;
  33. this.strength = strength;
  34. this.brand = "Maxgood House";
  35. }
  36. pour(amount = 1) {
  37. return `${super.pour(amount)}, but it sucks`;
  38. }
  39. };
  40. boring = new MaxgoodHouse("Boring");
  41. boring.brew();
  42. alert(boring.pour());
  43. JCoffee = class JCoffee {
  44. constructor(name1, strength1 = 1, inventory = 0) {
  45. this.name = name1;
  46. this.strength = strength1;
  47. this.inventory = inventory;
  48. }
  49. pourClick() {
  50. return $(`#pour-${this.name}`).click((event) => {
  51. if (this.inventory !== 0) {
  52. this.inventory--;
  53. return alert(`Poured a cup of ${this.name}`);
  54. } else {
  55. return alert(`Out of ${this.name}`);
  56. }
  57. });
  58. }
  59. };
  60. j = new JCoffee("French", 2, 1);
  61. j.pourClick();
  62. SelectFlights = (function() {
  63. class SelectFlights {};
  64. constructor(SelectFlights.fetchingFlights = null)(function() {
  65. $("#tabs ul li a").bind({
  66. click: this.changeTab
  67. });
  68. $("#tabs #error a").click((event) => {
  69. event.preventDefault();
  70. return this.showFlights($("#tabs li a.active").attr("href"));
  71. });
  72. return {
  73. showFlights: function(activeDiv) {
  74. return {};
  75. },
  76. changeTab: (event) => {
  77. return {};
  78. }
  79. };
  80. });
  81. return SelectFlights;
  82. }).call(this);
  83. //# sourceMappingURL=6-1-class.js.map