Say I’m declaring a class Game.
class @Game
constructor: ->
@id = Game.generateNewGameId() # <---
player1: null
player2: null
@generateNewGameId: -> "blahblah23"
Here, I’m using generateNewGameId as Game.generateNewGameId().
Is this the right way or is there a better way? I’ve tried using this::generateNewGameId() but the scope’s different.
If you really want
generateNewGameIdto be a class method then you can use@constructorto get at it:So something like this:
Note that this will do The Right Thing if you subclass
Game:Demo (open your console please): http://jsfiddle.net/ambiguous/Vz2SE/