Is there a way to create some type of variable that is the same in every instance of a JavaScript Class (no global variables)?
For example:
function Class(){
this.foo = 'bar';
this.setText = setText;
this.getText = getText;
}
function setText(value){
this.foo = value;
}
function getText(){
alert(this.foo);
}
Now I create two instances of the same class like so:
var fruit = new Class();
var groceries = new Class();
When I change the value of foo in the class fruit I also want it to be changed in groceries.
fruit.setText("apple");
fruit.getText(); //alerts apple
groceries.getText(); //SHOULD also alert apple
I am creating the instances of a class dynamically, they don't have a clear variable names (fruit, groceries) like in the example.
Thanks!