継承を実装する関数があります:
inherit = function(base) {
var child = function() { console.log('Crappy constructor.'); };
child.prototype = new base;
child.prototype.constructor = child;
return child;
}
次のように使用できると思いました。
var NewClass = inherit(BaseClass);
NewClass.prototype.constructor = function() {
console.log('Awesome constructor.');
}
しかし、次のようにNewClassの新しいインスタンスを作成すると:
var instance = new NewClass();
Crappy constructorというメッセージが表示されます。コンソールに出力されています。コンストラクターが上書きされないのはなぜですか? また、どうすれば上書きできますか?