I have Googled and also checked Stack Overflow answers for this. But I am not able to understand clearly on this. Can anyone help explain simply the following example please?
function myObject(){
this.iAm = 'an object';
myObject.prototype.values = "value";
this.whatAmI = function(){
alert('I am ' + this.iAm);
}
}
var myObject1 = new myObject();
myObject1.values = "value2";
myObject1.iAm = "New";
alert(myObject1.values);
var myObject2 = new myObject();
alert(myObject1.values);
In the above code if I use this.iAm
, it behaves in the same way prototype behaves.
I am new to Javascript Object Oriented Programming.
I expect many down votes. But I'm not concerned with that, because I just want to receive an explanation in a clear and simple way, that I have been able to find yet.