Skip to content

Instantly share code, notes, and snippets.

@alexkalderimis
Created March 13, 2012 12:49
Show Gist options
  • Save alexkalderimis/2028563 to your computer and use it in GitHub Desktop.
Save alexkalderimis/2028563 to your computer and use it in GitHub Desktop.
Nice namespace API for coffeescript
root = exports ? this
unless root.console
root.console =
log: ->
debug: ->
error: ->
namespace = (path, code = ->) ->
parts = path.split "."
ns = root
for part in parts
ns = if ns[part] then ns[part] else (ns[part] = {})
public = (cls) ->
ns[cls.name] = cls
code(public)
return ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment