//es6
? ? class parent{
? ? ? ? ?constructor() {
? ? ? ? ?this.age =18
? ? ? ? }
}
class Childextends parent{
?constructor() {
? super();
? ? ? ? ? ? this.name ='烏拉'
? ? ? ? }
}
let ab =new Child();
console.log(ab.age,ab.name)
//es5原型鏈繼承
function Parent(){
this.age =18
}
function Child(){
this.name ='烏拉'
}
Child.prototype =new Parent();
let ab =new Child();
console.log(ab.age,ab.name)