I have:
Master object
function Fruit() {
this.type = \"fruit\";
}
Sub-object:
function Bannana() {
this.color =
This is so cool. If you go this way:
function Fruit() {
this.type = "fruit";
}
function Bannana() {
this.color = "yellow";
}
Bannana.prototype = new Fruit;
Bannana.prototype.type='flower';
var myBanana = new Bannana();
console.log( myBanana.type );
you will get a "flower", but if you go this way:
function Fruit() {
this.type = "fruit";
}
function Bannana() {
Fruit.call(this);
this.color = "yellow";
}
Bannana.prototype.type='flower';
var myBanana = new Bannana();
console.log( myBanana.type );
You will get a "fruit";
I believe no explanation needed, right?