class Animal{
constructor(){...}
walk(){ console.log('Animal walking...')}
}
class Mammal extends Animal{
constructor(){...}
walk(){console.log('Mammal walking...')}
}
class Cat extends Mammal{
constructor(){}
walk(){console.log('Cat walking...')}
}
在上面的類層次結構,我想打電話給動物的步行()從貓實施對象如何調用JavaScript對象的根類方法?
我想:
class Cat extends Mammal{
constructor(){}
walk(){
super.super.walk()
}
}
但我得到的錯誤:
Uncaught TypeError: Cannot read property 'walk' of undefined
你可以試試 - >'動物.prototype.walk.call(c)' – Keith
'Animal.prototype.walk()',如果你想在chi的上下文中調用它, ld class'Animal.prototype.walk.call(c)' – taha
@Keith,taha:那有效。非常感謝 – Naveen