IFE第四十二天到第四十三天:开一家餐厅吧(一)

task1(ES5)

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>IFE ECMAScript</title>
</head>

<body>

    <script>
        var id = 0;

        function generateID() {
            return ++id;
        }

        function Restaurant(attr) {
            this.cash = attr.cash;
            this.seats = attr.seats;
            this.staff = attr.staff;
        }

        Restaurant.prototype.hire = function (staff) {
            this.staff.push(staff);
        }

        Restaurant.prototype.fire = function (staff) {
            this.staff = this.staff.filter(function (el) {
                return el !== staff;
            });
        }

        function Staff(name, salary) {
            this.id = generateID();
            this.name = name;
            this.salary = salary;
        }

        Staff.prototype.work = function () {

        }

        function Waiter(name, salary) {
            Staff.call(this, name, salary);
        }

        // Waiter.prototype = new Staff();
        Waiter.prototype = Object.create(Staff.prototype);
        Waiter.prototype.construstor = Waiter;
        Waiter.prototype.serve = function (orderlist) {
            if (Array.isArray(orderlist)) {
                this.list = orderlist;
            } else {
                console.log("上菜");
            }
        }

        function Cook(name, salary) {
            Staff.call(this, name, salary);
        }

        // Cook.prototype = new Staff();
        Cook.prototype = Object.create(Staff.prototype);
        Cook.prototype.construstor = Cook;
        Cook.prototype.serve = function () {
            console.log("烹饪");
        }

        function Customer() {

        }

        Customer.prototype.order = function () {
            console.log("点菜");
        }
        Customer.prototype.eat = function () {
            console.log("吃菜");
        }

        function Dish(dishname, cost, price) {
            this.dishname = dishname;
            this.cost = cost;
            this.price = price;
        }

        var ifeRestaurant = new Restaurant({
            cash: 1000000,
            seats: 20,
            staff: []
        });

        var newCook = new Cook("Tony", 10000);
        var newCook2 = new Cook("James", 10000);
        ifeRestaurant.hire(newCook);
        ifeRestaurant.hire(newCook2)

        console.log(ifeRestaurant.staff);

        ifeRestaurant.fire(newCook);
        console.log(ifeRestaurant.staff);
    </script>
</body>

</html>

task2(ES6)

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>IFE ECMAScript</title>
</head>

<body>

    <script>
        var id = 0;

        function generateID() {
            return ++id;
        }

        class Restaurant {
            constructor(attr) {
                this.cash = attr.cash;
                this.seats = attr.seats;
                this.staff = attr.staff;
            }
            hire(staff) {
                this.staff.push(staff);
            }
            fire(staff) {
                this.staff = this.staff.filter(function (el) {
                    return el !== staff;
                });
            }
        }

        class Staff {
            constructor(name, salary) {
                this.id = generateID();
                this.name = name;
                this.salary = salary;
            }
            work() {}
        }

        class Waiter extends Staff {
            constructor(name, salary) {
                super(name, salary);
            }
            serve(orderlist) {
                if (Array.isArray(orderlist)) {
                    this.list = orderlist;
                } else {
                    console.log("上菜");
                }
            }
        }

        class Cook extends Staff {
            constructor(name, salary) {
                super(name, salary);
            }
            serve() {
                console.log("烹饪");
            }
        }

        class Customer {
            order() {
                console.log("点菜");
            }
            eat() {
                console.log("吃菜");
            }
        }

        class Dish {
            constructor(dishname, cost, price) {
                this.dishname = dishname;
                this.cost = cost;
                this.price = price;
            }
        }

        var ifeRestaurant = new Restaurant({
            cash: 1000000,
            seats: 20,
            staff: []
        });

        var newCook = new Cook("Tony", 10000);
        var newCook2 = new Cook("James", 10000);
        ifeRestaurant.hire(newCook);
        ifeRestaurant.hire(newCook2)

        console.log(ifeRestaurant.staff);

        ifeRestaurant.fire(newCook);
        console.log(ifeRestaurant.staff);
    </script>
</body>

</html>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值