class Department{
constructor(){
console.log('parent class')
}
}
class Employee extends Department{
constructor(){
super()
console.log('child constructor method')
}
findName(){
console.log('Vimal');
}
}
let E1 = new Employee(); console.log(E1.findName())
现在在上面的代码中,它给我的日志为“父类”“子构造函数方法”“用户名”未定义现在这个未定义来自哪里任何人都可以帮助我理解这一点
这个功能,
findName(){
console.log('Vimal');
}
返回
undefined
(默认情况下,在 JavaScript 中,不显式返回某些内容的函数 - return undefined
)。
所以当你做
console.log(E1.findName())
时,你做了两件事:
Vidal
将被记录E1.findName()
的返回值。该函数返回 undefined
,因此确实记录了 undefined
。