这就是我尝试组织原型的方式:
但是我必须编写一个额外的“方法”属性来访问原型的功能是相当低效的。
var Gallery = function(name) {
this.name = name;
}
Gallery.prototype.methods = {
activeCnt: 0,
inc: function() {
this.activeCnt++;
},
dec: function() {
this.activeCnt--;
},
talk: function() {
alert(this.activeCnt);
}
}
var artGallery = new Gallery('art');
var carGallery = new Gallery('car');
artGallery.methods.inc();
artGallery.methods.talk();
carGallery.methods.talk();