如何从继承对象调用超级构造函数?例如,我有一个简单的动物“类”:
function Animal(legs) {
this.legs = legs;
}
我想创建一个从 Animal 继承但将腿数设置为随机数的“Chimera”类(在构造函数中提供最大腿数。到目前为止,我有这个:
function Chimera(maxLegs) {
// generate [randLegs] maxed to maxLegs
// call Animal's constructor with [randLegs]
}
Chimera.prototype = new Animal;
Chimera.prototype.constructor = Chimera;
如何调用 Animal 的构造函数?谢谢