Mamy sobie taki prosty kod z przykładami dziedziczenia moje pytanie jest następujące. Czy można dziedziczy/prototypować konkretny obiekt w klasie (wiem wiem w JS nie ma klas)
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
this.isAlive = true;
}
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}
function Emperor(name) {
this.name = name;
this.saying = "Waddle waddle";
}
// set up the prototype chain
Penguin.prototype = new Animal();
Emperor.prototype = new Penguin();
var myEmperor = new Emperor("Jules");
console.log(myEmperor.saying); // should print "Waddle waddle"
console.log(myEmperor.numLegs); // should print 2
console.log(myEmperor.isAlive); // should print true
A ja bym chciał teraz Aby Emperor
pobierało z klasy Animal
this.numLegs = numLegs;
Czy da radę zrobić coś na kształt
Emperor.prototype.numLegs = Animal.numLegs
tak by po wpisaniu
var myEmperor = new Emperor("Jules",5);
console.log(myEmperor.numLegs);
wyrzucał 5
dodanie znaczników <code class="javascript"> oraz `` - fp