class Parent{
constructor(name='hkj'){
this.name=name;
}
static fun(){ //定义静态方法(类可直接调用,不需要生成对象)
alert("this is static function");
Parent.type="parent type"; //静态属性
Parent.fun(); //调用静态方法
alert(Parent.type); //调用静态属性
class Child extends Parent{ //继承父类
constructor(name="hukai"){
super(name); //子类构造函数第一行必须显示调用父类构造函数
this.type="child";
}
set setName(name){ //set属性!!!不是方法
this.name=name;
}
get getName(){ //get属性
return "childName:"+this.name;
}
}
let child=new Child();
console.log(child.name);
console.log(child.type);
let child1=new Child("hukaijing");
constructor(name='hkj'){
this.name=name;
}
static fun(){ //定义静态方法(类可直接调用,不需要生成对象)
alert("this is static function");
}
}
Parent.type="parent type"; //静态属性
Parent.fun(); //调用静态方法
alert(Parent.type); //调用静态属性
class Child extends Parent{ //继承父类
constructor(name="hukai"){
super(name); //子类构造函数第一行必须显示调用父类构造函数
this.type="child";
}
set setName(name){ //set属性!!!不是方法
this.name=name;
}
get getName(){ //get属性
return "childName:"+this.name;
}
}
let child=new Child();
console.log(child.name);
console.log(child.type);
let child1=new Child("hukaijing");
console.log(child1.name)
console.log(child1.type);