call

        //call继承主要是继承构造函数中的属性
        function Person(age, sex) {
            this.age = age;
            this.sex = sex;
        }
        Person.prototype.Sleep = function () {
            console.log("睡觉");
        }
        Person.prototype.eat = function () {
            console.log("吃饭");
        }
        function Student(score,age,sex) {
            this.score = score;
            Person.call(this,age,sex)
        }
        Student.prototype.Play=function(){
            console.log("别问,就是打球");
        }
        let stu1=new Student(120,18,"男");
        console.log(stu1.age+"\t"+stu1.sex+"\t"+stu1.score);
        stu1.Play();
        // stu1.eat();//报错
上一篇:c语言:结构体复习


下一篇:面向过程编程和面向对象编程