new个空对象去继承

113 阅读1分钟
<script>
        function Person() { }
        Person.prototype.head = 1;
        Person.prototype.foot = 2;
        /* 子类 */
        function Student() {
            this.name = 'zhangsan';
            this.no = '9587';
        }
        function extend(child,parent) {
            let F = function () { };
            F.prototype = parent.prototype;
            child.prototype = new F();
            child.prototype.constructor = child;
        }
        extend(Student,Person);
        let stu1 = new Student();
        console.log(stu1)
        // Student.prototype.car = '奥迪';
        // /* 原型里面的构造器是指向构造函数本身的 */
        // console.log(Person.prototype);
    </script>
    ```