Классы в Coffeescript 'Namespace'

Я нашел этот фрагмент в FAQ по Coffeescript для создания упрощенных пространств имен ..

# Code:
#
namespace = (target, name, block) ->
  [target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
  top    = target
  target = target[item] or= {} for item in name.split '.'
  block target, top

# Usage:
#
namespace 'Hello.World', (exports) ->
  # `exports` is where you attach namespace members
  exports.hi = -> console.log 'Hi World!'

namespace 'Say.Hello', (exports, top) ->
  # `top` is a reference to the main namespace
  exports.fn = -> top.Hello.World.hi()

Say.Hello.fn()  # prints 'Hi World!'

Это все хорошо, но у меня большие проблемы с тем, чтобы сделать это с ключевым словом class . Так что ..

namespace 'Project.Something', (exports) ->
   exports.something = -> class something
    // .. code here
   exports.somethingElse = class somethingElse extends something

может кто-нибудь пролить свет на синтаксис, с помощью которого можно это сделать?

14
задан Ciel 4 January 2012 в 17:07
поделиться