階層を構築するときに、javascript オブジェクトの「コンストラクター」プロパティをサブクラスに設定する必要性を理解するのに苦労しています。以下のコードは、コンストラクターのプロパティを変更せずに期待されることを実行することがわかりましたが、ほとんどすべての参考文献で、コンストラクターが明示的に設定されています。何か不足していますか?(ECMAScript 仕様でも明示的な使用は見当たりません)。
A = function() {
this.value = "a";
this.A = function() {
window.alert( this.value + " instanceof A : " + ( this instanceof A ) );
}
}
B = function() {
this.value = "b";
this.B = function() {
window.alert( this.value + " instanceof B : " + ( this instanceof B ) );
}
}
B.prototype = new A();
test = function() {
var b = new B();
b.A();
b.B();
}