Last active
August 29, 2015 14:00
-
-
Save bahelms/0989756c71de02e70886 to your computer and use it in GitHub Desktop.
How to namespace in 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
# Node.js is exports; Rails is window | |
global = if typeof exports isnt 'undefined' then exports else window | |
global.namespace = (target, name, block) -> | |
[target, name, block] = [global, arguments...] if arguments.length < 3 | |
top = target | |
target = target[item] or= {} for item in name.split '.' | |
block target, top | |
# Declare your class | |
namespace "NS", (global) -> | |
class global.HtmlCanvas | |
# Use your class | |
NS.HtmlCanvas() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment