class Father{
say(){
console.log('father')
}
}
class Son extends Father{
say(){
console.log(super.say())
}
}
let son = new Son();
son.say()
为什么打印出来第一个是father,会出现第二个是undefined
第一个是father
super.say()
调用的是继承对象的方法,所以打印的是"father";
会出现第二个是undefined
son.say
里console.log
打印super.say()
的返回值。
在子类中 super
关键字用于调用父类的方法或者属性 直接调用super
则调用父类的构造函数
调用子类的say方法的时候,传递了一个参数,参数是父类 Father.say
的调用结果, 没有返回值,默认返回 undefined
所以第一次打印 father
第二次打印undefined