js 继承

//父类
class Person{
    constructor(name) {
        this.name = name
    }
    eat(){
        console.log(`${this.name} eat something`)
    }
}

//子类
class Student extends Person{
    constructor(name,number) {
        super(name);
        this.number = number
    }
    sayHI(){
        console.log(`姓名 ${this.name} 学号 ${this.number} `)
    }
}

//实列
const std = new Student('周瑜',333)
std.sayHI()
std.eat()

 

//父类
class Person{
constructor(name) {
this.name = name
}
eat(){
console.log(`${this.name} eat something`)
}
}

//子类
class Student extends Person{
constructor(name,number) {
super(name);
this.number = number
}
sayHI(){
console.log(`姓名 ${this.name} 学号 ${this.number} `)
}
}

//实列
const std = new Student('周瑜',333)
std.sayHI()
std.eat()
posted @ 2020-05-04 11:52  夏天的西瓜君  阅读(160)  评论(0编辑  收藏  举报