ES5继承

作者: Time_Notes | 来源:发表于2020-05-21 23:03 被阅读0次

function SuperType(surname){

    this.surname= surname;

}

SuperType.prototype.saySurame = function(){

    alert(this.surname);

}

function SubType(surname, lastname, gender){

    SuperType.call(this,surname);

    this.lastname = lastname;

    this.gender = gender;

}

SubType.prototype = Object.create(SuperType.prototype); //原型链接

SubType.prototype.constructor = SubType; //修正constructor

SubType.prototype.sayLastname = function(){

    alert(this.lastname);

}


实例的原型链 实例原型链 构造函数A的原型链 构造函数A的原型链 构造函数B的原型链 构造函数B的原型链

相关文章

网友评论

      本文标题:ES5继承

      本文链接:https://www.haomeiwen.com/subject/isfcvhtx.html