Witam,
Fragment kodu wygląda tak:
function Footballer(first, surname, club, strongFoot){
this.first=first;
this.surname=surname;
this.club=club;
this.foot=strongFoot;
}
//change club
Footballer.prototype.changeClub = function(newClub){
return `${this.first} ${this.surname} moves to ${this.club=newClub}.`;
}
//get some informations about the player
Footballer.prototype.informations = function(){
return `${this.first} ${this.surname}, plays in ${this.club}.`;
}
function Goalkeeper(first, surname, club, defStyle){
Footballer.call(this, first, surname, club);
this.defStyle=defStyle;
}
Goalkeeper.prototype = Object.create(Footballer.prototype, {});
Czyli konstruktor obiektu Goalkeeper przejmuje właściwości i metody konstruktora Footballer. Natomiast wedle poradników w sieci, należy jeszcze zmienić prototyp samego konstruktora Goalkeeper (po wykonaniu powyższego kodu jego prototypem jest konstruktor Footballer:
Goalkeeper.prototype.constructor = Goalkeeper;
Nie jest wyjaśnione, czemu ma służyć ta linijka. Zmienia ona to:
constructor: ƒ Footballer(first, surname, club, strongFoot)
na poniższe.
constructor: ƒ Goalkeeper(first, surname, club, defStyle)
Nieobecność tej linijki nie powoduje żadnych błędów, stąd moje pytanie: co daje nam wyżej przytoczona zmiana właściwości Goalkeeper.prototype.constructor, skoro nic nie zmienia to w sposobie działania konstruktora?
Przepraszam za takie nawarstwienie informacji, ale uczę się JSa krótko i dopiero przyswajam te zagadnienia.
Z góry dziękuję.