ES6继承问题
class Father{
say(){
console.log('father')
}
}
class Son extends Father{
say(){
console.log(super.say())
}
}
let son = new Son();
son.say()
为什么打印出来第一个是father,会出现第二个是undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
super.say()
调用的是继承对象的方法,所以打印的是"father";son.say
里console.log
打印super.say()
的返回值。在子类中
super
关键字用于调用父类的方法或者属性 直接调用super
则调用父类的构造函数调用子类的say方法的时候,传递了一个参数,参数是父类
Father.say
的调用结果, 没有返回值,默认返回undefined
所以第一次打印
father
第二次打印undefined