浏览代码

Finish objects-method restaurant model

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 年之前
父节点
当前提交
c716b35588
共有 1 个文件被更改,包括 28 次插入0 次删除
  1. 28 0
      objects-methods.js

+ 28 - 0
objects-methods.js

@@ -0,0 +1,28 @@
+let restaurant = {
+    name: 'Red Lobster',
+    guestCapacity: 75,
+    guestCount: 0,
+    checkAvailability: function (partySize) {
+        let seatsLeft = this.guestCapacity - this.guestCount
+
+        return partySize <= seatsLeft
+    },
+    seatParty: function (guests) {
+        this.guestCount = this.guestCount + guests
+        console.log(`seating ${guests}, total is now ${this.guestCount}/${this.guestCapacity}.`)
+    },
+    removeParty: function(guests) {
+        this.guestCount = this.guestCount - guests
+        console.log(`${guests} leaving, total is now ${this.guestCount}/${this.guestCapacity}.`)
+    }
+}
+
+// seatParty
+
+// removeParty
+
+restaurant.seatParty(72)
+console.log(restaurant.checkAvailability(4))
+restaurant.removeParty(5)
+console.log(restaurant.checkAvailability(4))
+