Sharing same properties across different class instances
by colintoh
JavaScript
var Gallery = function(name,age) {
this.name = name;
this.age = parseInt(age);
}
Gallery.prototype.galleryCnt = 5;
Gallery.prototype.incAge = function() {
this.age++;
}
Gallery.prototype.incCnt = function() {
Gallery.prototype.galleryCnt++;
}
Gallery.prototype.decCnt = function() {
Gallery.prototype.galleryCnt--;
}
Gallery.prototype.talk = function() {
alert(this.galleryCnt+" " +this.name+" "+this.age);
}
var art = new Gallery('Art Festival',9);
var car = new Gallery('Car Garage',9);
car.incCnt();
car.decCnt();
art.incAge();
car.talk();
art.talk();