I have an object called superCar. I have a function Car. I would like to inherit my Car Object from superCar Object. Here is my code:
var superCar = {
model : "sedan"
};
function Car(){
this.name = null;
}
var c1 = new Car();
c1.name="Toyota";
var c2 = new Car();
c2.name="Bmw";
console.log(c1.name);
console.log(c2.name);
c1.__proto__.__proto__ = superCar.__proto__ ;
console.log(c1.model);
I am expecting the out put will be "Toyota" , "Bmw" , "sedan". But the output is comming out as "Toyota" , "Bmw" , "undefined". Can any one of you please explain why my inheritance did not work?