js 继承
2021-03-12 16:31
标签:class student this style ext pre div new cto js 继承 标签:class student this style ext pre div new cto 原文地址:https://www.cnblogs.com/yangxuming/p/12825977.html//父类
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()
上一篇:PHP使用引用实现无限极分类