while i was reading about prototype in javascript, I had a question.
Let's say I have the following functions and objects
Function #1:
function Rectangle(w,h){
this.width = w;
this.height = h;
this.area = function(){return this.width * this.height}
}
var object1 = new Rectangle(10,5);
var object11 = new Rectangle(5,5);
Function #2:
function Rectangle(w,h){
this.width = w;
this.height = h;
}
Rectangle.prototype.area = function(){ return this.width * this.height; }
var object2 = new Rectangle(10,5);
var object22 = new Rectangle(5,5);
As far as I understand object2 and object22 use less memory than object1 and object11 because function #2 uses prototype.
is this correct?