Ответ 1
Вы можете определить методы класса, префикс их с помощью @
:
class Box2DUtility
constructor: () ->
@drawWorld: (world, context) -> alert 'World drawn!'
# And then draw your world...
Box2DUtility.drawWorld()
Демо: http://jsfiddle.net/ambiguous/5yPh7/
И если вы хотите, чтобы ваш drawWorld
работал как конструктор, вы можете сказать new @
следующим образом:
class Box2DUtility
constructor: (s) -> @s = s
m: () -> alert "instance method called: #{@s}"
@drawWorld: (s) -> new @ s
Box2DUtility.drawWorld('pancakes').m()