-1
这是我如何尝试组织原型:组织对象原型的更好方法是什么?
但是,我必须编写额外的“方法”属性来访问原型的功能是相当低效的。
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();
这是什么问题?您想做什么? – gdoron
你的第一句话似乎表明它跟随着它,但它不在那里...?此外,这不是一个真正的代码审查和建议网站。根据FAQ,我认为这不是一个有效的问题。 –