Hi everyone,
I was wondering what was the problem in my code.
I want my function Bird to inherit all the methods from my Animal constructor.
I would want to Bird to be able to access the Animal constructor & get the informations as this.*
EDIT : i used the prototype way to manage to get some answers while caling the Bird prototype, but still can’t access to the Animal informations … sadly
Your code so far
class Animal {
constructor(name, age, color, personnality) {
this.name = name;
this.age = age;
this.color = color;
this.personnality = personnality;
this.presentation = function() {
console.log(`Cela peut paraitre étonannt oui, mais mon prénom est ${this.name}, j'ai ${this.age} mais attention, je suis ${this.color}`);
};
}
}
Bird.prototype = Object.create(Animal.prototype);
//Bird.prototype = new Animal;
function Bird() { }
Bird.prototype = {
constructor: Bird,
eat: function() {
console.log("i am eating well, thanks");
}
};
let bolo = new Bird('Roger', 5, 'rouge');
//For this element, i am switching with Bird & Animal, while i type Bird, it can't access to the presentation function.
bolo.eat(); //Uncaught TypeError TypeError: bolo.presentation is not a function
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Object Oriented Programming - Use Inheritance So You Don’t Repeat Yourself
Link to the challenge: