// class 关键词
class Person{
constructor(name){
//当前类型的构造函数
this.name = name
}
static classMT(){
return '静态方法'
}
say(){
console.log(`hi ${this.name}`)
}
}
// static 静态方法
console.log(Person.classMT()) // 静态方法
class students extends Person{
constructor(name,number){
super(name)
this.number = number
}
hello(){
super.say()
console.log(`hello,my name is ${this.name},我的学号是${this.number}`)
}
}
const s = new students('jack',18)
s.hello() // hello,my name is jack,我的学号是18
s.say() // hi jack
class类,static静态方法,extendes继承
最新推荐文章于 2024-07-26 20:46:33 发布