class类构造函数
作者:互联网
class类构造函数
class Hero{
constructor(aname,atype,aword){
this.aname = aname
this.atype = atype
this.aword = aword
}
sayWord(){
alert(`${this.aname}说${this.aword}`)
}
}
//细化类:extends 创建子类 super调用父类的方法【作为对象】
class Fuzhu extends Hero{
constructor(aname,atype,aword,www){
super(aname,atype,aword)//使用this之前子类要调用super【作为方法使用】
this.www = www
}
sayWord(){
super.sayWord()
alert(`游走`)
}
}
let yao = new Fuzhu('瑶','辅助','小鹿女啊,一定是世界上最不可爱的孩子吧','游走')
console.log(yao)
yao.sayWord()
标签:aword,atype,aname,sayWord,super,class,构造函数 来源: https://blog.csdn.net/XEstrus/article/details/110312841