私はこのコードを持っています:
var MyClass = function(b) {
this.a = b;
this.getA = function() {
return that.a;
}
}
var SecondClass = function(b) {
this.prototype = new MyClass(b);
this.getB = function() {
return 6;
}
}
var a = new SecondClass(2);
console.log(a.getA());
出力は、 getA() というメソッドがないことを示しています
SecondClass のコンストラクター内で this.prototype = new MyClass() を実行すると、MyClass からメソッドが継承されると思いましたか?
これを行うためのより良い方法があると確信していますが、prototype キーワードの動作を理解しようとしています。