【发布时间】:2013-05-27 12:17:51
【问题描述】:
方法一:
Rectangle.prototype.getArea = function() {
return this.length * this.width;
};
方法二:
Rectangle.prototype = {
getArea: function() {
return this.length * this.width;
}
};
上述每种方法的区别和优势是什么?
【问题讨论】:
-
与处理普通对象时一样,第二种样式会破坏
prototype的所有现有内容。 -
这与
x += 10vsx = 10基本相同。
标签: javascript oop prototype