js 继承

2021-03-12 16:31

阅读:585

标签:class   student   this   style   ext   pre   div   new   cto   

//父类
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()

js 继承

标签:class   student   this   style   ext   pre   div   new   cto   

原文地址:https://www.cnblogs.com/yangxuming/p/12825977.html


评论


亲,登录后才可以留言!