父级构造函数
function Father(){
this.type = "人类";
}
子级构造函数
function Son(name,age) {
this.name = name;
this.age = age
}
如果使子级继承父级
方法1:call或者apply。如果需要传参按照call和apply的传参即可。
function Son(name,age){
Father.apply(this); //或者Father.call(this)
this.name = name;
this.age = age;
}
JS构造函数继承---------通过call或者apply继承父级属性
最新推荐文章于 2022-03-17 13:36:56 发布