原型继承

68 阅读1分钟
     //Person人类 - 父类
     function Person() {
            this.name = 'jack'
        }
        Person.prototype.eat = function () {
            console.log('吃饭')
        }

        //Student学生类 -子类
        function Student() {
            this.num = 1001
        }

        //原型继承 - 父类实例对象赋值给子类原型
        Student.prototype = new Person()

        let s1 = new Student()
        s1.eat()
        console.log(s1.name);