Is these two code snippets using Object Prototype are exactly same?

32 views Asked by At
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?

  1. In the first snippet, there is two function showNameAndClor and amIOrganic which is set using Plant.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 ?*
0

There are 0 answers