Just create a nested object in the constructor.
function Game() { this.stats = { lives: 3 }; }; var a = new Game(); -- a.stats.lives;
However, this can be annoying, since when implementing the Game you must refer to stats as this.stats . A reset of this ' es can occur when this refers to the wrong thing, for example, inside a function(){} expression.
My preferred template looks like this. This is essentially the classic OO gatekeeper feature.
function Game() { var stats = { lives: 3 }; this.stats = function() { return stats; }; }; var a = new Game(); -- a.stats().lives;
source share