原型继承 2022年3月7日

90 阅读1分钟

原型继承

```<script>
    //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);


</script>