<分区>
哪个是更好的 Javascript 对象模式...
function dog(name) {
this.name = name;
this.getName = function() {
return this.name;
};
};
或
function cat(name) {
this.name = name;
};
cat.prototype.getName = function() {
return this.name;
};
为什么?
----- 编辑
哪一个占用更多内存?
一个“CPU”密集度比另一个高还是低?
哪个更易于维护?
哪个更具可扩展性?
哪个更具可读性?