第一种:
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype.add= function () {
return this.x
};
var p = new Point(1, 2);
第二种:
function point2(x,y){
var o = {};
o.x = x;
o.y = y;
o.add= function(){
return o.x
}
return o
}
var p1 = point2(1,2)
请问两者之间的差异?
相关分类