class Human{
static str = 'aaa';
sayStr = ()=>{
throw new Error('need to implement');
}
}
class Student extends Human{
constructor(){
super();
}
sayStr(){
console.log(Student.str)
}
}
const leo = new Student();
console.log(Student.str);
leo.sayStr();
答案
aaa
need to implement
解析:
1. 在 ES6 中类的继承是可以继承静态属性的
2. 在 class 里,用 = 声明的变量属于 Field declarations 的语法,leo 的 sayStr 被挂载到了实例属性上,读取优先于原型链