For exampleis this:
function obj(val) {
this.val = val;
}
obj.prototype.newfunction = function(){
return this.val;
};
Different than this in any way at all?
function obj(val) {
this.val = val;
this.newfunction = function(){
return this.val;
}
}
I realize that the reason for prototype
is so that you can add methods to objects that you didn't create, but is there any reason to use the second block over the first, or vice versa?