I try to access an object which is global; it's a kind of a preset.
var perks = {health: 100, attack: 10};
var player = function(hp) {
this.stats = perks;
//Changing some standard values..
this.stats["health"] = hp;
}
var Peter = new player(200);
var Steven = new player(300);
I hope you get my intention; the problem is, that it won't work correct, and I'm not even sure what it does wrong. If I create more than one player, e.g. Steven, Collin and James, every player has the same perks. In this example Peter and Steven both have 300 health.
If I change the line
this.stats = perks;
to
this.stats = {health: 100, attack: 10};
everything works like intended. Peter and Steven both have their own stats.
How do I access the global var perks?
perks