继承

    function SuperType(name,age) {
        this.name = name;
        this.age = age;
    }
    SuperType.prototype.sayName = function(){
        console.log(this.name);
    }

    function SubType(name,age,sex) {
        SuperType.call(this,name,age);
        this.sex = sex;
    }
    SubType.prototype = new SuperType();
    SubType.prototype.constructor = SubType;
    SubType.prototype.saySex = function(){
        console.log(this.sex);
    }
    let obj = new SubType('ls','26','male');
    console.log(Object.getPrototypeOf(obj))

 

posted on 2018-10-15 17:46  weblsy  阅读(108)  评论(0编辑  收藏  举报