I think the path you are accessing is fine. You can also do @constructor.generateNewGameId() if you don't want to write Game.generateNewGameId() for some reason, but I would prefer later. Update: as @mu is too short to mention , @constructor allows you to get an instance constructor that may be different from Game (in a subclass), so it has more flexibility; if in this case such flexibility is required, we will definitely go for it :)
If the generateNewGameId function is not accessible from outside the Game class, you can use the private function instead of the class method:
class @Game gameIdCounter = 0 generateNewGameId = -> gameIdCounter++ constructor: -> @id = generateNewGameId() player1: null player2: null console.log (new Game).id # -> 0 console.log (new Game).id # -> 1
Example at coffeescript.org .
There, both gameIdCounter and generateNewGameId are private variables inside the Game class.
source share