mam ten kod:Przypisywanie prototyp wewnątrz konstruktora
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());
Wyjście mówi mi, że nie ma metody nazywanej Geta()
Sądziłem, że robi this.prototype = new MyClass() wewnątrz konstruktor dla SecondClass spowodowałby, że odziedziczyłby metody z MyClass?
Jestem pewien, że istnieją lepsze sposoby, aby to zrobić, ale staram się zrozumieć zachowanie prototypowego słowa kluczowego.
"Prototype" nie jest słowem kluczowym. – Pointy
'return that.a;' powinno być 'return this.a;' btw. –