<script>
class Parent{
constructor() {
this.age = 18
}
}
class Child extends Parent {
constructor() {
super()
this.name = '张三'
}
}
let ol = new Child()
console.log(ol,ol.name,ol.age);
</script>
2: 原型链继承
<script>
function Parent() {
this.age = 20;
}
function Child() {
this.name = "张三";
}
Child.prototype = new Parent()
let o = new Child();
console.log(o, o.name, o.age);
</script>
3:call 继承
<script>
function Parent() {
this.age = 10;
}
function Child() {
Parent.call(this)
this.name = "张三";
}
let o = new Child();
console.log(o, o.name, o.age);
</script>