面向对象编程

    function inherits(Child,Parent){
        var F = function(){};
        F.prototype = Parent.prototype;
        Child.prototype = new F();
        Child.prototype.constructor = Child;
    }
    function Student(props){
        this.name = props.name || 'WangXiang';
    };
    Student.prototype.hello = function(){
        alert('Hello,' + this.name + '!')
    };
    function PrimaryStudent(props){
        Student.call(this,props);
        this.grade = props.grade || 43;
    }
    inherits(PrimaryStudent,Student);
    PrimaryStudent.prototype.getGrade = function(){
        return this.grade;
    }

 

posted @ 2018-09-04 23:02  LaLaLa_heng  阅读(66)  评论(0编辑  收藏  举报