//构造函数的继承
function Father(name, age) {
this.name = name
this.age = 20
this.skill = function () {
console.log('coding');
}
}
function Son(height, weight) {
Father.call(this, 'ls')
this.height = height
this.weight = weight
}
let son1 = new Son(21, 20)
console.log(son1);
//class类的继承
class Father2 {
constructor(name, age) {
this.name = name
this.age = 20
}
skill() {
console.log('11212121');
}
}
class Son2 extends Father2 {
constructor(height, weight) {
super('zs')
this.height = height
this.weight = weight
}
}
let son2 = new Son2(30, 50)
console.log(son2);
01-10
470
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交