ES5继承

2020-05-21  本文已影响0人  Time_Notes

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的原型链
上一篇 下一篇

猜你喜欢

热点阅读