Created
March 13, 2012 12:49
-
-
Save alexkalderimis/2028563 to your computer and use it in GitHub Desktop.
Nice namespace API for coffeescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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