这两个对象创建方法的方式有什么不同吗?是否存在性能差异?这有什么区别,如果有的话?
方法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;
};
};
方法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;
};