function Plant () {
this.country = "Mexico";
this.isOrganic = true;
}
Plant.prototype.showNameAndColor = function () {
console.log("I am a " + this.name + " and my color is " + this.color);
}
Plant.prototype.amIOrganic = function () {
if (this.isOrganic)
console.log("I am organic, Baby!");
}
Is the above code is similar to the below code ???
function Plant () {
this.country = "Mexico";
this.isOrganic = true;
this.showNameAndColor = function () {
console.log("I am a " + this.name + " and my color is " + this.color);
}
this.prototype.amIOrganic = function () {
if (this.isOrganic)
console.log("I am organic, Baby!");
}
}
*1. Is the above two code snippets are exactly similar?
- In the first snippet, there is two function
showNameAndClor
andamIOrganic
which is set usingPlant.Prototype
does it mean all the new objects which are going to inherit the Plant object can access these two functions only other than their own properties ?*