var Player = function() { this.inventory = {}; this.ship = {}; this.state = {}; this.addItem = function(key, delta) { if (this.inventory[key] == null) { this.inventory[key] = delta; } else { this.inventory[key] += delta; } return this.inventory[key]; }; this.getItem = function(key) { return this.inventory[key]; }; this.getData = function(key) { return this.state[key]; }; this.setData = function(key, value) { this.state[key] = value; return this.state[key]; }; this.getShip = function(key) { return this.ship[key]; } this.setShip = function(key, value) { this.ship[key] = value; return this.ship[key]; }; this.addShip = function(key, delta) { if (this.ship[key] == null) { this.ship[key] = delta; } else { this.ship[key] += delta; } return this.ship[key]; }; }; var player = new Player();