Is there any difference in the way these two objects create their methods? Are there performance differences? What's the difference here, if any?
Method 1:
var Point = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
this.add = function(point) {
this.x += point.x;
this.y += point.y;
this.z += point.z;
};
this.sub = function(point) {
this.x -= point.x;
this.y -= point.y;
this.z -= point.z;
};
};
Method 2:
var Point = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
Point.prototype.add = function(point) {
this.x += point.x;
this.y += point.y;
this.z += point.z;
};
Point.prototype.sub = function(point) {
this.x -= point.x;
this.y -= point.y;
this.z -= point.z;
};