我见过这个问题,我知道如何扩展一个类。但是,用方法做到这一点是一种好习惯吗?使用它是否安全:
function extendClass(child, parent) {
child.prototype = Object.create(parent.prototype);
child.constructor = child;
}
extendClass(Banana, Fruit);
而不是这个:
Banana.prototype = Object.create(Fruit.prototype);
Banana.prototype.constructor = Banana;