使用或不使用有什么区别prototype
?他们显然也是这样做的。
与prototype
:
function poligon(angles){
this.angles = angles;
}
poligon.prototype.color = function(){ return "blue"; }
var mypol = new poligon(14);
alert(mypol.color());
没有prototype
:
function poligon(angles){
this.angles = angles;
}
poligon.color = function(){ return "blue"; }
var mypol = new poligon(12);
alert(poligon.color());
添加带有prototype
和不带有它的“颜色”对象的真正含义是什么?